Skip to content

Commit d2ff273

Browse files
Apply suggestions from code review
Co-authored-by: cgoetz-inovex <carlo.goetz@inovex.de>
1 parent e577341 commit d2ff273

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

internal/cmd/auth/api/get-access-token/get_access_token.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,13 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
4949
return &cliErr.SessionExpiredError{}
5050
}
5151

52-
switch model.OutputFormat {
53-
case print.JSONOutputFormat:
54-
details, err := json.MarshalIndent(map[string]string{
55-
"access_token": accessToken,
56-
}, "", " ")
57-
if err != nil {
58-
return fmt.Errorf("marshal access token: %w", err)
59-
}
60-
params.Printer.Outputln(string(details))
61-
62-
return nil
63-
default:
52+
result := map[string]string{
53+
"access_token": accessToken,
54+
}
55+
return params.Printer.OutputResult(model.OutputFormat, result, func() error {
6456
params.Printer.Outputln(accessToken)
65-
6657
return nil
67-
}
58+
})
6859
},
6960
}
7061

internal/cmd/auth/api/status/status.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
8585
}
8686

8787
func outputStatus(p *print.Printer, model *inputModel, status statusOutput) error {
88-
switch model.OutputFormat {
89-
case print.JSONOutputFormat:
90-
details, err := json.MarshalIndent(status, "", " ")
91-
if err != nil {
92-
return fmt.Errorf("marshal status: %w", err)
93-
}
94-
p.Outputln(string(details))
95-
return nil
96-
default:
88+
return p.OutputResult(model.OutputFormat, status, func() error {
9789
if status.Authenticated {
9890
p.Outputln("API Authentication Status: Authenticated")
9991
if status.Email != "" {
@@ -105,5 +97,5 @@ func outputStatus(p *print.Printer, model *inputModel, status statusOutput) erro
10597
p.Outputln("\nTo authenticate, run: stackit auth api login")
10698
}
10799
return nil
108-
}
100+
})
109101
}

internal/pkg/auth/auth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ func debugHTTPResponse(p *print.Printer, resp *http.Response) {
278278
if p == nil || resp == nil {
279279
return
280280
}
281+
if !p.IsVerbosityDebug() {
282+
return
283+
}
281284

282285
p.Debug(print.DebugLevel, "=== HTTP RESPONSE ===")
283286
p.Debug(print.DebugLevel, "Status: %s", resp.Status)

0 commit comments

Comments
 (0)