@@ -79,7 +79,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7979 return fmt .Errorf ("create MariaDB credentials: %w" , err )
8080 }
8181
82- return outputResult (p , model , instanceLabel , resp )
82+ return outputResult (p , model . OutputFormat , model . ShowPassword , instanceLabel , resp )
8383 },
8484 }
8585 configureFlags (cmd )
@@ -123,11 +123,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API
123123 return req
124124}
125125
126- func outputResult (p * print.Printer , model * inputModel , instanceLabel string , resp * mariadb.CredentialsResponse ) error {
127- if ! model .ShowPassword {
126+ func outputResult (p * print.Printer , outputFormat string , showPassword bool , instanceLabel string , resp * mariadb.CredentialsResponse ) error {
127+ if resp == nil {
128+ return fmt .Errorf ("response is nil" )
129+ }
130+
131+ if ! showPassword && resp .HasRaw () && resp .Raw .Credentials != nil {
128132 resp .Raw .Credentials .Password = utils .Ptr ("hidden" )
129133 }
130- switch model . OutputFormat {
134+ switch outputFormat {
131135 case print .JSONOutputFormat :
132136 details , err := json .MarshalIndent (resp , "" , " " )
133137 if err != nil {
@@ -151,7 +155,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res
151155 if username := resp .Raw .Credentials .Username ; username != nil && * username != "" {
152156 p .Outputf ("Username: %s\n " , * username )
153157 }
154- if ! model . ShowPassword {
158+ if ! showPassword {
155159 p .Outputf ("Password: <hidden>\n " )
156160 } else {
157161 p .Outputf ("Password: %s\n " , utils .PtrString (resp .Raw .Credentials .Password ))
0 commit comments