@@ -79,7 +79,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7979 return fmt .Errorf ("create credentials for Observability instance: %w" , err )
8080 }
8181
82- return outputResult (p , model , instanceLabel , resp )
82+ return outputResult (p , model . OutputFormat , instanceLabel , resp )
8383 },
8484 }
8585 configureFlags (cmd )
@@ -110,8 +110,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *observabili
110110 return req
111111}
112112
113- func outputResult (p * print.Printer , model * inputModel , instanceLabel string , resp * observability.CreateCredentialsResponse ) error {
114- switch model .OutputFormat {
113+ func outputResult (p * print.Printer , outputFormat , instanceLabel string , resp * observability.CreateCredentialsResponse ) error {
114+ if resp == nil {
115+ return fmt .Errorf ("response is nil" )
116+ }
117+
118+ switch outputFormat {
115119 case print .JSONOutputFormat :
116120 details , err := json .MarshalIndent (resp , "" , " " )
117121 if err != nil {
@@ -130,13 +134,14 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res
130134 return nil
131135 default :
132136 p .Outputf ("Created credentials for instance %q.\n \n " , instanceLabel )
133- // The username field cannot be set by the user, so we only display it if it's not returned empty
134- username := * resp .Credentials .Username
135- if username != "" {
136- p .Outputf ("Username: %s\n " , username )
137- }
138137
139138 if resp .Credentials != nil {
139+ // The username field cannot be set by the user, so we only display it if it's not returned empty
140+ username := * resp .Credentials .Username
141+ if username != "" {
142+ p .Outputf ("Username: %s\n " , username )
143+ }
144+
140145 p .Outputf ("Password: %s\n " , utils .PtrString (resp .Credentials .Password ))
141146 }
142147 return nil
0 commit comments