Skip to content

Commit

Permalink
add co2 compensation msg with spinner (#82)
Browse files Browse the repository at this point in the history
* add co2 compensation msg with spinner
  • Loading branch information
Nemat97 authored Mar 12, 2024
1 parent 3f82fdb commit bba8ae3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions create/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bba8ae3

Please sign in to comment.