From b8a0dcf763493fbd0e5c8603ea83092fe903e1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Palet?= Date: Wed, 8 May 2024 10:42:17 +0100 Subject: [PATCH 1/3] Make pretty the default output for LB describe commands --- .../cmd/load-balancer/describe/describe.go | 10 +++++----- .../describe/describe.go | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/cmd/load-balancer/describe/describe.go b/internal/cmd/load-balancer/describe/describe.go index 610d31e40..cdb899168 100644 --- a/internal/cmd/load-balancer/describe/describe.go +++ b/internal/cmd/load-balancer/describe/describe.go @@ -37,8 +37,8 @@ func NewCmd(p *print.Printer) *cobra.Command { `Get details of a load balancer with name "my-load-balancer"`, "$ stackit load-balancer describe my-load-balancer"), examples.NewExample( - `Get details of a load-balancer with name "my-load-balancer" in a table format`, - "$ stackit load-balancer describe my-load-balancer --output-format pretty"), + `Get details of a load-balancer with name "my-load-balancer" in a JSON format`, + "$ stackit load-balancer describe my-load-balancer --output-format JSON"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() @@ -97,9 +97,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *loadbalance func outputResult(p *print.Printer, outputFormat string, loadBalancer *loadbalancer.LoadBalancer) error { switch outputFormat { - case print.PrettyOutputFormat: - return outputResultAsTable(p, loadBalancer) - default: + case print.JSONOutputFormat: details, err := json.MarshalIndent(loadBalancer, "", " ") if err != nil { return fmt.Errorf("marshal load balancer: %w", err) @@ -107,6 +105,8 @@ func outputResult(p *print.Printer, outputFormat string, loadBalancer *loadbalan p.Outputln(string(details)) return nil + default: + return outputResultAsTable(p, loadBalancer) } } diff --git a/internal/cmd/load-balancer/observability-credentials/describe/describe.go b/internal/cmd/load-balancer/observability-credentials/describe/describe.go index 91a0024ab..31d109501 100644 --- a/internal/cmd/load-balancer/observability-credentials/describe/describe.go +++ b/internal/cmd/load-balancer/observability-credentials/describe/describe.go @@ -95,7 +95,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *loadbalance func outputResult(p *print.Printer, outputFormat string, credentials *loadbalancer.GetCredentialsResponse) error { switch outputFormat { - case print.PrettyOutputFormat: + case print.JSONOutputFormat: + details, err := json.MarshalIndent(credentials, "", " ") + if err != nil { + return fmt.Errorf("marshal Load Balancer observability credentials: %w", err) + } + p.Outputln(string(details)) + + return nil + default: table := tables.NewTable() table.AddRow("REFERENCE", *credentials.Credential.CredentialsRef) table.AddSeparator() @@ -108,14 +116,6 @@ func outputResult(p *print.Printer, outputFormat string, credentials *loadbalanc return fmt.Errorf("render table: %w", err) } - return nil - default: - details, err := json.MarshalIndent(credentials, "", " ") - if err != nil { - return fmt.Errorf("marshal Load Balancer observability credentials: %w", err) - } - p.Outputln(string(details)) - return nil } } From c2ec86148075dbb0a07de94636108ba27e183697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Palet?= Date: Wed, 8 May 2024 10:46:56 +0100 Subject: [PATCH 2/3] Prompt for password when adding credentials before prompt for confirmation --- .../observability-credentials/add/add.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/cmd/load-balancer/observability-credentials/add/add.go b/internal/cmd/load-balancer/observability-credentials/add/add.go index 1a7148e58..ea47bff29 100644 --- a/internal/cmd/load-balancer/observability-credentials/add/add.go +++ b/internal/cmd/load-balancer/observability-credentials/add/add.go @@ -66,23 +66,23 @@ func NewCmd(p *print.Printer) *cobra.Command { projectLabel = model.ProjectId } - if !model.AssumeYes { - prompt := fmt.Sprintf("Are you sure you want to add observability credentials for Load Balancer on project %q?", projectLabel) - err = p.PromptForConfirmation(prompt) - if err != nil { - return err - } - } - // Prompt for password if not passed in as a flag if model.Password == nil { - pwd, err := p.PromptForPassword("Enter password: ") + pwd, err := p.PromptForPassword("Enter user password: ") if err != nil { return fmt.Errorf("prompt for password: %w", err) } model.Password = utils.Ptr(pwd) } + if !model.AssumeYes { + prompt := fmt.Sprintf("Are you sure you want to add observability credentials for Load Balancer on project %q?", projectLabel) + err = p.PromptForConfirmation(prompt) + if err != nil { + return err + } + } + // Call API req := buildRequest(ctx, model, apiClient) resp, err := req.Execute() From 3b05226642a0558a081b205713ae866c9440b657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Palet?= Date: Wed, 8 May 2024 10:48:18 +0100 Subject: [PATCH 3/3] Fix capitalization in example --- internal/cmd/load-balancer/describe/describe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/load-balancer/describe/describe.go b/internal/cmd/load-balancer/describe/describe.go index cdb899168..9cbf6547d 100644 --- a/internal/cmd/load-balancer/describe/describe.go +++ b/internal/cmd/load-balancer/describe/describe.go @@ -38,7 +38,7 @@ func NewCmd(p *print.Printer) *cobra.Command { "$ stackit load-balancer describe my-load-balancer"), examples.NewExample( `Get details of a load-balancer with name "my-load-balancer" in a JSON format`, - "$ stackit load-balancer describe my-load-balancer --output-format JSON"), + "$ stackit load-balancer describe my-load-balancer --output-format json"), ), RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background()