@@ -86,7 +86,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
8686 return fmt .Errorf ("create Secrets Manager user: %w" , err )
8787 }
8888
89- return outputResult (p , model , instanceLabel , resp )
89+ return outputResult (p , model . OutputFormat , instanceLabel , resp )
9090 },
9191 }
9292
@@ -137,30 +137,34 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *secretsmana
137137 return req
138138}
139139
140- func outputResult (p * print.Printer , model * inputModel , instanceLabel string , resp * secretsmanager.User ) error {
141- switch model .OutputFormat {
140+ func outputResult (p * print.Printer , outputFormat , instanceLabel string , user * secretsmanager.User ) error {
141+ if user == nil {
142+ return fmt .Errorf ("user is nil" )
143+ }
144+
145+ switch outputFormat {
142146 case print .JSONOutputFormat :
143- details , err := json .MarshalIndent (resp , "" , " " )
147+ details , err := json .MarshalIndent (user , "" , " " )
144148 if err != nil {
145149 return fmt .Errorf ("marshal Secrets Manager user: %w" , err )
146150 }
147151 p .Outputln (string (details ))
148152
149153 return nil
150154 case print .YAMLOutputFormat :
151- details , err := yaml .MarshalWithOptions (resp , yaml .IndentSequence (true ), yaml .UseJSONMarshaler ())
155+ details , err := yaml .MarshalWithOptions (user , yaml .IndentSequence (true ), yaml .UseJSONMarshaler ())
152156 if err != nil {
153157 return fmt .Errorf ("marshal Secrets Manager user: %w" , err )
154158 }
155159 p .Outputln (string (details ))
156160
157161 return nil
158162 default :
159- p .Outputf ("Created user for instance %q. User ID: %s\n \n " , instanceLabel , utils .PtrString (resp .Id ))
160- p .Outputf ("Username: %s\n " , utils .PtrString (resp .Username ))
161- p .Outputf ("Password: %s\n " , utils .PtrString (resp .Password ))
162- p .Outputf ("Description: %s\n " , utils .PtrString (resp .Description ))
163- p .Outputf ("Write Access: %s\n " , utils .PtrString (resp .Write ))
163+ p .Outputf ("Created user for instance %q. User ID: %s\n \n " , instanceLabel , utils .PtrString (user .Id ))
164+ p .Outputf ("Username: %s\n " , utils .PtrString (user .Username ))
165+ p .Outputf ("Password: %s\n " , utils .PtrString (user .Password ))
166+ p .Outputf ("Description: %s\n " , utils .PtrString (user .Description ))
167+ p .Outputf ("Write Access: %s\n " , utils .PtrString (user .Write ))
164168
165169 return nil
166170 }
0 commit comments