From bba8ae31850a7c32a79b527f5f1321a1fcc58546 Mon Sep 17 00:00:00 2001 From: Nemat97 <111134947+Nemat97@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:25:19 +0100 Subject: [PATCH] add co2 compensation msg with spinner (#82) * add co2 compensation msg with spinner --- create/application.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/create/application.go b/create/application.go index 2f3e547..2157e3a 100644 --- a/create/application.go +++ b/create/application.go @@ -165,7 +165,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { if err := c.createResource(appWaitCtx); err != nil { if auth.Enabled() { secret := auth.Secret(newApp) - if gitErr := client.Delete(ctx, secret); err != nil { + if gitErr := client.Delete(ctx, secret); gitErr != nil { return errors.Join(err, fmt.Errorf("unable to delete git auth secret: %w", gitErr)) } } @@ -189,7 +189,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { } } if releaseErr, ok := err.(releaseError); ok { - if err := releaseErr.printMessage(appWaitCtx, client, newApp); err != nil { + if err := releaseErr.printMessage(appWaitCtx, client); err != nil { return fmt.Errorf("%s: %w", releaseErr, err) } } @@ -200,6 +200,10 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } + if err := spinnerMessage("co2 compensating the app 🌳", 2*time.Second); err != nil { + return err + } + fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) @@ -224,6 +228,18 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return nil } +func spinnerMessage(msg string, sleepTime time.Duration) error { + spinner, err := format.NewSpinner(msg, msg) + if err != nil { + return err + } + if err := spinner.Start(); err != nil { + return err + } + time.Sleep(sleepTime) + return spinner.Stop() +} + func (app *applicationCmd) config() apps.Config { var deployJob *apps.DeployJob @@ -430,7 +446,7 @@ func (r releaseError) Error() string { return fmt.Sprintf("release failed with status %s", r.release.Status.AtProvider.ReleaseStatus) } -func (r releaseError) printMessage(ctx context.Context, client *api.Client, app *apps.Application) error { +func (r releaseError) printMessage(ctx context.Context, client *api.Client) error { fmt.Printf("\nYour release has failed with status %q. Here are the last %v lines of the log:\n\n", r.release.Status.AtProvider.ReleaseStatus, errorLogLines) return printReleaseLogs(ctx, client, r.release)