From 261d523b87317d9579257bb0f80ba16aa6b2ba1f Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 13:35:52 +0100 Subject: [PATCH 1/9] add co2 compensation msg with spinner --- create/application.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/create/application.go b/create/application.go index 2f3e547..cf43579 100644 --- a/create/application.go +++ b/create/application.go @@ -200,6 +200,8 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } + return co2compensation() + fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) @@ -224,6 +226,19 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return nil } +func co2compensation() error { + msg := "CO2 compensated 🍃, we are saving the world" + spinner, err := format.NewSpinner(msg, msg) + if err != nil { + return err + } + if err := spinner.Start(); err != nil { + return err + } + time.Sleep(2 * time.Second) + return spinner.Stop() +} + func (app *applicationCmd) config() apps.Config { var deployJob *apps.DeployJob From 1c862f50d6ee0688a1afafda1b0b5e67b5a25533 Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 14:23:58 +0100 Subject: [PATCH 2/9] change the msg --- create/application.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create/application.go b/create/application.go index cf43579..2295edc 100644 --- a/create/application.go +++ b/create/application.go @@ -227,7 +227,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { } func co2compensation() error { - msg := "CO2 compensated 🍃, we are saving the world" + msg := "CO2 compensated.🌿 Saving the world, one CO2 molecule at a time 💨." spinner, err := format.NewSpinner(msg, msg) if err != nil { return err From d79c1cde20b99d61ccef1894ee122397405f4a42 Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 14:28:42 +0100 Subject: [PATCH 3/9] fix: function call --- create/application.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create/application.go b/create/application.go index 2295edc..93f2152 100644 --- a/create/application.go +++ b/create/application.go @@ -200,7 +200,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } - return co2compensation() + co2compensation() fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) From 7e6a507149d3d22871df8c6633fafef9e131da53 Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 15:35:02 +0100 Subject: [PATCH 4/9] rename the function and add parameters --- create/application.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/create/application.go b/create/application.go index 93f2152..cdb249b 100644 --- a/create/application.go +++ b/create/application.go @@ -200,7 +200,8 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } - co2compensation() + msg := "" + spinnerMessage(msg, -2*time.Second) fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) @@ -226,8 +227,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return nil } -func co2compensation() error { - msg := "CO2 compensated.🌿 Saving the world, one CO2 molecule at a time 💨." +func spinnerMessage(msg string, sleepTime time.Duration) error { spinner, err := format.NewSpinner(msg, msg) if err != nil { return err @@ -235,7 +235,7 @@ func co2compensation() error { if err := spinner.Start(); err != nil { return err } - time.Sleep(2 * time.Second) + time.Sleep(sleepTime) return spinner.Stop() } From 374b9925491264fd9d69c4428516a57403defb15 Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 15:40:02 +0100 Subject: [PATCH 5/9] fix --- create/application.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create/application.go b/create/application.go index cdb249b..982c3ed 100644 --- a/create/application.go +++ b/create/application.go @@ -200,8 +200,8 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } - msg := "" - spinnerMessage(msg, -2*time.Second) + msg := "co2 compensating the app 🌳" + spinnerMessage(msg, 2*time.Second) fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) From f23e45f5c628fad49944a5f53ece1e67fc0b0133 Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 16:05:01 +0100 Subject: [PATCH 6/9] format --- create/application.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create/application.go b/create/application.go index 982c3ed..60ad0d5 100644 --- a/create/application.go +++ b/create/application.go @@ -200,8 +200,8 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } - msg := "co2 compensating the app 🌳" - spinnerMessage(msg, 2*time.Second) + msg := " co2 compensating the app 🌳" + spinnerMessage(msg, 10) fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) From c297a0ebe59220937cc1cd60b77f7ba6c5333207 Mon Sep 17 00:00:00 2001 From: nemat97 Date: Fri, 8 Mar 2024 16:13:26 +0100 Subject: [PATCH 7/9] format --- create/application.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create/application.go b/create/application.go index 60ad0d5..982c3ed 100644 --- a/create/application.go +++ b/create/application.go @@ -200,8 +200,8 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } - msg := " co2 compensating the app 🌳" - spinnerMessage(msg, 10) + msg := "co2 compensating the app 🌳" + spinnerMessage(msg, 2*time.Second) fmt.Printf("\nYour application %q is now available at:\n https://%s\n\n", newApp.Name, newApp.Status.AtProvider.CNAMETarget) printUnverifiedHostsMessage(newApp) From 0d481e97b56b7e0c2b865dcc1898eac35c24e2fe Mon Sep 17 00:00:00 2001 From: nemat97 Date: Tue, 12 Mar 2024 11:49:47 +0100 Subject: [PATCH 8/9] fix: add error raturn value --- create/application.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/create/application.go b/create/application.go index 982c3ed..50667e9 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) } } @@ -201,7 +201,9 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { } msg := "co2 compensating the app 🌳" - spinnerMessage(msg, 2*time.Second) + if err := spinnerMessage(msg, 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) @@ -445,7 +447,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) From 1f8be0a63d7ce5770e24e9578f5345418030a80c Mon Sep 17 00:00:00 2001 From: nemat97 Date: Tue, 12 Mar 2024 12:20:09 +0100 Subject: [PATCH 9/9] set the msg in the func --- create/application.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/create/application.go b/create/application.go index 50667e9..2157e3a 100644 --- a/create/application.go +++ b/create/application.go @@ -200,8 +200,7 @@ func (app *applicationCmd) Run(ctx context.Context, client *api.Client) error { return err } - msg := "co2 compensating the app 🌳" - if err := spinnerMessage(msg, 2*time.Second); err != nil { + if err := spinnerMessage("co2 compensating the app 🌳", 2*time.Second); err != nil { return err }