@@ -78,7 +78,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7878 return fmt .Errorf ("create LogMe credentials: %w" , err )
7979 }
8080
81- return outputResult (p , model , instanceLabel , resp )
81+ return outputResult (p , model . OutputFormat , model . ShowPassword , instanceLabel , resp )
8282 },
8383 }
8484 configureFlags (cmd )
@@ -122,11 +122,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl
122122 return req
123123}
124124
125- func outputResult (p * print.Printer , model * inputModel , instanceLabel string , resp * logme.CredentialsResponse ) error {
126- if ! model .ShowPassword {
125+ func outputResult (p * print.Printer , outputFormat string , showPassword bool , instanceLabel string , resp * logme.CredentialsResponse ) error {
126+ if resp == nil {
127+ return fmt .Errorf ("credentials response is empty" )
128+ }
129+
130+ if ! showPassword && resp .HasRaw () && resp .Raw .Credentials != nil {
127131 resp .Raw .Credentials .Password = utils .Ptr ("hidden" )
128132 }
129- switch model . OutputFormat {
133+ switch outputFormat {
130134 case print .JSONOutputFormat :
131135 details , err := json .MarshalIndent (resp , "" , " " )
132136 if err != nil {
@@ -150,7 +154,7 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res
150154 if username := resp .Raw .Credentials .Username ; username != nil && * username != "" {
151155 p .Outputf ("Username: %s\n " , utils .PtrString (username ))
152156 }
153- if ! model . ShowPassword {
157+ if ! showPassword {
154158 p .Outputf ("Password: <hidden>\n " )
155159 } else {
156160 p .Outputf ("Password: %s\n " , utils .PtrString (resp .Raw .Credentials .Password ))
0 commit comments