Skip to content

Commit

Permalink
cmd/create: Start spinner earlier
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HarryMichal committed Mar 21, 2021
1 parent a8c6fd1 commit 3aaa1d3
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3aaa1d3

Please sign in to comment.