diff options
author | Leandro Alves <ldalves@gmail.com> | 2021-11-29 09:33:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-29 09:33:52 +0100 |
commit | 2016d2ef25b2000bd31c44e80c8d704080a4bc2b (patch) | |
tree | 8eaafcd73ad7ad34087ca5e52d2fe05a28e8da13 | |
parent | 3e42751c8c7ad6e68b1558c74ad76a2ca13bbf8b (diff) | |
parent | 69117dc281a44d6562afc340f58d1887ab5178d7 (diff) |
Merge pull request #20200 from vespa-engine/ldalves/spinner
Fix spinner for the 'deploy' command
-rw-r--r-- | client/go/auth0/auth0.go | 5 | ||||
-rw-r--r-- | client/go/cmd/clone.go | 4 | ||||
-rw-r--r-- | client/go/cmd/deploy.go | 4 | ||||
-rw-r--r-- | client/go/util/spinner.go | 15 | ||||
-rw-r--r-- | client/go/vespa/deploy.go | 7 |
5 files changed, 18 insertions, 17 deletions
diff --git a/client/go/auth0/auth0.go b/client/go/auth0/auth0.go index 52a1997d957..bcde790f830 100644 --- a/client/go/auth0/auth0.go +++ b/client/go/auth0/auth0.go @@ -167,6 +167,7 @@ func (a *Auth0) PrepareSystem(ctx context.Context) (System, error) { if err != nil { // ask and guide the user through the login process: fmt.Println(fmt.Errorf("failed to renew access token, %s", err)) + fmt.Print("\n") s, err = RunLogin(ctx, a, true) if err != nil { return System{}, err @@ -371,9 +372,9 @@ func RunLogin(ctx context.Context, a *Auth0, expired bool) (System, error) { } var res auth.Result - util.Spinner("Waiting for login to complete in browser ...", func() error { + err = util.Spinner("Waiting for login to complete in browser ...", func() error { res, err = a.Authenticator.Wait(ctx, state) - return nil + return err }) if err != nil { diff --git a/client/go/cmd/clone.go b/client/go/cmd/clone.go index e4bbd751f8a..6fe3c0d5a29 100644 --- a/client/go/cmd/clone.go +++ b/client/go/cmd/clone.go @@ -142,7 +142,7 @@ func getSampleAppsZip() *os.File { return f } - util.Spinner(color.Yellow("Downloading sample apps ...").String(), func() error { + err = util.Spinner(color.Yellow("Downloading sample apps ...").String(), func() error { request, err := http.NewRequest("GET", "https://github.com/vespa-engine/sample-apps/archive/refs/heads/master.zip", nil) if err != nil { fatalErr(err, "Invalid URL") @@ -162,7 +162,7 @@ func getSampleAppsZip() *os.File { fatalErr(err, "Could not write sample apps to file: ", f.Name()) return nil } - return nil + return err }) return f diff --git a/client/go/cmd/deploy.go b/client/go/cmd/deploy.go index 813abe88069..ae39afc3773 100644 --- a/client/go/cmd/deploy.go +++ b/client/go/cmd/deploy.go @@ -65,9 +65,7 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`, target := getTarget() opts := getDeploymentOpts(cfg, pkg, target) - sessionOrRunID, err = vespa.Deploy(opts) - - if err == nil { + if sessionOrRunID, err := vespa.Deploy(opts); err == nil { fmt.Print("\n") if opts.IsCloud() { printSuccess("Triggered deployment of ", color.Cyan(pkg.Path), " with run ID ", color.Cyan(sessionOrRunID)) diff --git a/client/go/util/spinner.go b/client/go/util/spinner.go index 5e6522c3990..9f3c2cb4e44 100644 --- a/client/go/util/spinner.go +++ b/client/go/util/spinner.go @@ -3,7 +3,6 @@ package util import ( - "fmt" "os" "time" @@ -19,18 +18,18 @@ const ( var messages = os.Stderr -func Spinner(text string, fn func() error) { +func Spinner(text string, fn func() error) error { initialMsg := text + " " doneMsg := "\r" + initialMsg + spinnerTextDone + "\n" failMsg := "\r" + initialMsg + spinnerTextFailed + "\n" - loading(initialMsg, doneMsg, failMsg, fn) + return loading(initialMsg, doneMsg, failMsg, fn) } -func Waiting(fn func() error) { - loading("", "", "", fn) +func Waiting(fn func() error) error { + return loading("", "", "", fn) } -func loading(initialMsg, doneMsg, failMsg string, fn func() error) { +func loading(initialMsg, doneMsg, failMsg string, fn func() error) error { done := make(chan struct{}) errc := make(chan error) go func() { @@ -59,9 +58,7 @@ func loading(initialMsg, doneMsg, failMsg string, fn func() error) { errc <- err <-done - if err != nil { - fmt.Println(fmt.Errorf("an unexpected error occurred: %w", err)) - } + return err } func Error(e error, message string) error { diff --git a/client/go/vespa/deploy.go b/client/go/vespa/deploy.go index 741b45f9e15..d52fc969c37 100644 --- a/client/go/vespa/deploy.go +++ b/client/go/vespa/deploy.go @@ -374,7 +374,12 @@ func uploadApplicationPackage(url *url.URL, opts DeploymentOpts) (int64, error) if err := opts.Target.PrepareApiRequest(request, sigKeyId); err != nil { return 0, err } - response, err := util.HttpDo(request, time.Minute*10, serviceDescription) + + var response *http.Response + err = util.Spinner("Uploading application package ...", func() error { + response, err = util.HttpDo(request, time.Minute*10, serviceDescription) + return err + }) if err != nil { return 0, err } |