From 3c01270cf2503bf2b20c64c9698bf9c571f3a5a1 Mon Sep 17 00:00:00 2001 From: Aris Buzachis Date: Thu, 11 Jan 2024 12:27:37 +0200 Subject: [PATCH] fix: do not print to stdout for stylish format for env actions Signed-off-by: Aris Buzachis --- cmd/component/action/update.go | 2 +- cmd/environment/action/clone.go | 6 ++- cmd/environment/action/create.go | 2 +- cmd/environment/action/delete.go | 2 +- cmd/environment/action/deploy.go | 2 +- cmd/environment/action/root.go | 44 +++++++++++-------- cmd/environment/action/start.go | 12 +++-- cmd/environment/action/stop.go | 12 +++-- cmd/environment/action/update.components.go | 14 ++++-- .../action/update.configuration.go | 2 +- 10 files changed, 64 insertions(+), 34 deletions(-) diff --git a/cmd/component/action/update.go b/cmd/component/action/update.go index c9cf2f9..2d11079 100644 --- a/cmd/component/action/update.go +++ b/cmd/component/action/update.go @@ -88,7 +88,7 @@ func init() { deployOptions := &editOptions.DeployOptions deployOptions.ID = model.GetEnvironment() - if err = action.HandleDeploy(cmd, deployOptions, "updated", editComponentsData.K8SIntegration); err != nil { + if err = action.HandleDeploy(cmd, deployOptions, "updated", editComponentsData.K8SIntegration, settings.IsStylish()); err != nil { return err } diff --git a/cmd/environment/action/clone.go b/cmd/environment/action/clone.go index d3e1c32..a473948 100644 --- a/cmd/environment/action/clone.go +++ b/cmd/environment/action/clone.go @@ -26,7 +26,11 @@ func init() { return lib.FormatCommandError(cmd, err) } - cmd.Printf("\nEnvironment %s successfully cloned:\n\n", cloneOptions.ID) + printLogs := settings.IsStylish() + + if printLogs { + cmd.Printf("\nEnvironment %s successfully cloned:\n\n", cloneOptions.ID) + } return lib.FormatCommandData(cmd, model) }, diff --git a/cmd/environment/action/create.go b/cmd/environment/action/create.go index e85bca0..788bac7 100644 --- a/cmd/environment/action/create.go +++ b/cmd/environment/action/create.go @@ -99,7 +99,7 @@ func init() { deployOptions := &createOptions.DeployOptions deployOptions.ID = model.GetId() - return HandleDeploy(cmd, deployOptions, "created", createOptions.GetKubernetesIntegration()) + return HandleDeploy(cmd, deployOptions, "created", createOptions.GetKubernetesIntegration(), settings.IsStylish()) }, } diff --git a/cmd/environment/action/delete.go b/cmd/environment/action/delete.go index 20ff9af..0561513 100644 --- a/cmd/environment/action/delete.go +++ b/cmd/environment/action/delete.go @@ -34,7 +34,7 @@ func init() { return lib.FormatCommandData(cmd, event) } - if err = processEventPipeline(cmd, event, "deploy"); err != nil { + if err = processEventPipeline(cmd, event, "delete", settings.IsStylish()); err != nil { cmd.Printf("\nEnvironment %s deletion failed\n", deleteOptions.ID) return err diff --git a/cmd/environment/action/deploy.go b/cmd/environment/action/deploy.go index 640ce15..a8d3ee4 100644 --- a/cmd/environment/action/deploy.go +++ b/cmd/environment/action/deploy.go @@ -29,7 +29,7 @@ func init() { RunE: func(cmd *cobra.Command, args []string) error { deployOptions.ID = settings.Profile.Context.Environment - return HandleDeploy(cmd, deployOptions, "", deployData.K8SIntegration) + return HandleDeploy(cmd, deployOptions, "", deployData.K8SIntegration, settings.IsStylish()) }, } diff --git a/cmd/environment/action/root.go b/cmd/environment/action/root.go index 1888b23..3612f44 100644 --- a/cmd/environment/action/root.go +++ b/cmd/environment/action/root.go @@ -40,12 +40,12 @@ func validateActionOptions(actionOptions *common.ActionOptions) error { return fmt.Errorf("%w when following pipelines", lib.ErrNotStylish) } -func HandleDeploy(cmd *cobra.Command, deployOptions *environment.DeployOptions, action string, kubernetesIntegration string) error { +func HandleDeploy(cmd *cobra.Command, deployOptions *environment.DeployOptions, action string, kubernetesIntegration string, printLogs bool) error { if err := ensureKubernetesIntegration(deployOptions, kubernetesIntegration); err != nil { return err } - if action != "" { + if printLogs && action != "" { cmd.Printf("\nEnvironment %s successfully %s... deploying...\n", deployOptions.ID, action) } @@ -58,13 +58,17 @@ func HandleDeploy(cmd *cobra.Command, deployOptions *environment.DeployOptions, return lib.FormatCommandData(cmd, event) } - if err = processEventPipeline(cmd, event, "deploy"); err != nil { - cmd.Printf("\nEnvironment %s deploying failed\n", deployOptions.ID) + if err = processEventPipeline(cmd, event, "deploy", printLogs); err != nil { + if printLogs { + cmd.Printf("\nEnvironment %s deploying failed\n", deployOptions.ID) + } return err } - cmd.Printf("\nEnvironment %s successfully deployed\n", deployOptions.ID) + if printLogs { + cmd.Printf("\nEnvironment %s successfully deployed\n", deployOptions.ID) + } return showEnvironmentEndpoints(cmd, deployOptions.ID) } @@ -116,27 +120,31 @@ func ensureKubernetesIntegration(deployOptions *environment.DeployOptions, kuber return err } -func processEventPipeline(cmd *cobra.Command, event *sdk.EventItem, action string) error { +func processEventPipeline(cmd *cobra.Command, event *sdk.EventItem, action string, printLogs bool) error { progressOptions := progress.NewOptions() - cmd.Printf( - "Environment %s scheduled to %s with EventID %s\n", - event.GetEnvironment(), - action, - event.GetId(), - ) + if printLogs { + cmd.Printf( + "Environment %s scheduled to %s with EventID %s\n", + event.GetEnvironment(), + action, + event.GetId(), + ) + } pipeline, err := progress.EventToPipeline(event, progressOptions) if err != nil { return err } - cmd.Printf( - "EventID %s generated %s pipeline %s\n", - pipeline.GetEvent(), - action, - pipeline.GetId(), - ) + if printLogs { + cmd.Printf( + "EventID %s generated %s pipeline %s\n", + pipeline.GetEvent(), + action, + pipeline.GetId(), + ) + } if err = progress.Pipeline(pipeline.GetId(), nil); err != nil { return err diff --git a/cmd/environment/action/start.go b/cmd/environment/action/start.go index c55dd24..63307dc 100644 --- a/cmd/environment/action/start.go +++ b/cmd/environment/action/start.go @@ -34,13 +34,19 @@ func init() { return lib.FormatCommandData(cmd, event) } - if err = processEventPipeline(cmd, event, "start"); err != nil { - cmd.Printf("\nEnvironment %s starting failed\n", startOptions.ID) + printLogs := settings.IsStylish() + + if err = processEventPipeline(cmd, event, "start", printLogs); err != nil { + if printLogs { + cmd.Printf("\nEnvironment %s starting failed\n", startOptions.ID) + } return err } - cmd.Printf("\nEnvironment %s successfully started\n", startOptions.ID) + if printLogs { + cmd.Printf("\nEnvironment %s successfully started\n", startOptions.ID) + } return showEnvironmentEndpoints(cmd, startOptions.ID) }, diff --git a/cmd/environment/action/stop.go b/cmd/environment/action/stop.go index 7a37bbc..96bcd25 100644 --- a/cmd/environment/action/stop.go +++ b/cmd/environment/action/stop.go @@ -34,13 +34,19 @@ func init() { return lib.FormatCommandData(cmd, event) } - if err = processEventPipeline(cmd, event, "stop"); err != nil { - cmd.Printf("\nEnvironment %s stopping failed\n", stopOptions.ID) + printLogs := settings.IsStylish() + + if err = processEventPipeline(cmd, event, "stop", printLogs); err != nil { + if printLogs { + cmd.Printf("\nEnvironment %s stopping failed\n", stopOptions.ID) + } return err } - cmd.Printf("\nEnvironment %s successfully stopped\n", stopOptions.ID) + if printLogs { + cmd.Printf("\nEnvironment %s successfully stopped\n", stopOptions.ID) + } return nil }, diff --git a/cmd/environment/action/update.components.go b/cmd/environment/action/update.components.go index 37a540b..096100e 100644 --- a/cmd/environment/action/update.components.go +++ b/cmd/environment/action/update.components.go @@ -65,19 +65,25 @@ func init() { } if len(matched) == 0 { - cmd.Println("No components matched the filter") + cmd.PrintErrln("No components matched the filter") return nil } - cmd.Printf(`Updating components "%s"%s`, componentToString(matched), "\n\n") + printLogs := settings.IsStylish() + + if printLogs { + cmd.Printf(`Updating components "%s"%s`, componentToString(matched), "\n\n") + } model, err := environment.EditComponents(editOptions) if err != nil { return lib.FormatCommandError(cmd, err) } - cmd.Printf("Successfully updated Git details...%s", "\n\n") + if printLogs { + cmd.Printf("Successfully updated Git details...%s", "\n\n") + } if !editOptions.WithDeploy { return showGitInfo(cmd, model.GetId()) @@ -86,7 +92,7 @@ func init() { deployOptions := &editOptions.DeployOptions deployOptions.ID = model.GetId() - if err = HandleDeploy(cmd, deployOptions, "updated", editSource.K8SIntegration); err != nil { + if err = HandleDeploy(cmd, deployOptions, "updated", editSource.K8SIntegration, printLogs); err != nil { return err } diff --git a/cmd/environment/action/update.configuration.go b/cmd/environment/action/update.configuration.go index 0579851..37ff319 100644 --- a/cmd/environment/action/update.configuration.go +++ b/cmd/environment/action/update.configuration.go @@ -77,7 +77,7 @@ func init() { deployOptions := &editConfigurationOptions.DeployOptions deployOptions.ID = model.GetId() - return HandleDeploy(cmd, deployOptions, "updated", editConfigurationOptions.K8SIntegration) + return HandleDeploy(cmd, deployOptions, "updated", editConfigurationOptions.K8SIntegration, settings.IsStylish()) }, }