cmd/create: Start spinner earlier

Showing spinner after a lot of work on creating a toolbox is done (even
though not really time consuming) does not make much sense.

When a spinner is started successfully, a stop command is deferred.
There's no need to stop it additionally.
This commit is contained in:
Ondřej Míchal 2021-03-20 14:18:44 +01:00
parent a8c6fd19d8
commit 3aaa1d30f1

View file

@ -203,6 +203,17 @@ func createContainer(container, image, release string, showCommandToEnter bool)
return err
}
s := spinner.New(spinner.CharSets[9], 500*time.Millisecond)
stdoutFd := os.Stdout.Fd()
stdoutFdInt := int(stdoutFd)
if logLevel := logrus.GetLevel(); logLevel < logrus.DebugLevel && terminal.IsTerminal(stdoutFdInt) {
s.Prefix = fmt.Sprintf("Creating container %s: ", container)
s.Writer = os.Stdout
s.Start()
defer s.Stop()
}
toolboxPath := os.Getenv("TOOLBOX_PATH")
toolboxPathEnvArg := "TOOLBOX_PATH=" + toolboxPath
toolboxPathMountArg := toolboxPath + ":/usr/bin/toolbox:ro"
@ -458,23 +469,10 @@ func createContainer(container, image, release string, showCommandToEnter bool)
logrus.Debugf("%s", arg)
}
s := spinner.New(spinner.CharSets[9], 500*time.Millisecond)
stdoutFd := os.Stdout.Fd()
stdoutFdInt := int(stdoutFd)
if logLevel := logrus.GetLevel(); logLevel < logrus.DebugLevel && terminal.IsTerminal(stdoutFdInt) {
s.Prefix = fmt.Sprintf("Creating container %s: ", container)
s.Writer = os.Stdout
s.Start()
defer s.Stop()
}
if err := shell.Run("podman", nil, nil, nil, createArgs...); err != nil {
return fmt.Errorf("failed to create container %s", container)
}
s.Stop()
if showCommandToEnter {
fmt.Printf("Created container: %s\n", container)
fmt.Printf("Enter with: %s\n", enterCommand)