Skip to content

Commit

Permalink
Merge pull request #52 from aris-bunnyshell/fix/deploy-json
Browse files Browse the repository at this point in the history
fix: do not print to stdout for stylish format for env actions
  • Loading branch information
aris-bunnyshell authored Jan 12, 2024
2 parents 39d93d3 + 3c01270 commit cbc4126
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cmd/component/action/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/environment/action/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/environment/action/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/environment/action/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/environment/action/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
}

Expand Down
44 changes: 26 additions & 18 deletions cmd/environment/action/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions cmd/environment/action/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
12 changes: 9 additions & 3 deletions cmd/environment/action/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
14 changes: 10 additions & 4 deletions cmd/environment/action/update.components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/environment/action/update.configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
}

Expand Down

0 comments on commit cbc4126

Please sign in to comment.