Skip to content

Commit

Permalink
Allow specifying message to end the spinner with (#5972)
Browse files Browse the repository at this point in the history
* Allow specifying message to end the spinner with

For certain long running tasks, we need to specify a message that
doesn't confuse the user when the spinnner ends. This commit adds
`EndWithStatus` which is a wrapper on top of `End` and lets the
developer specify a custom message to end the spinner with.

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>

* Update pkg/devfile/adapters/kubernetes/component/commandhandler.go

Co-authored-by: Armel Soro <armel@rm3l.org>

Signed-off-by: Dharmit Shah <shahdharmit@gmail.com>
Co-authored-by: Armel Soro <armel@rm3l.org>
  • Loading branch information
dharmit and rm3l authored Aug 16, 2022
1 parent 53a7c3c commit 72d632b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (a *adapterHandler) Execute(devfileCmd devfilev1.Command) error {
// Creating with no spin because the command could be long-running, and we cannot determine when it will end.
s.Start(fmt.Sprintf("Executing the application (command: %s)", devfileCmd.Id), true)
case remotecmd.Stopped, remotecmd.Errored:
s.End(status == remotecmd.Stopped)
s.EndWithStatus(fmt.Sprintf("Finished executing the application (command: %s)", devfileCmd.Id), status == remotecmd.Stopped)
if err != nil {
klog.V(2).Infof("error while running background command: %v", err)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/log/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ func (s *Status) End(success bool) {
s.status = ""
}

// EndWithStatus is similar to End, but lets the user specify a custom message/status while ending
func (s *Status) EndWithStatus(status string, success bool) {
if status == "" {
return
}
s.status = status
s.End(success)
}

// Printf will output in an appropriate "information" manner; for e.g.
// • <message>
func Printf(format string, a ...interface{}) {
Expand Down

0 comments on commit 72d632b

Please sign in to comment.