@@ -79,7 +79,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7979 return fmt .Errorf ("create Redis credentials: %w" , err )
8080 }
8181
82- return outputResult (p , model , instanceLabel , resp )
82+ return outputResult (p , * model , instanceLabel , resp )
8383 },
8484 }
8585 configureFlags (cmd )
@@ -123,8 +123,20 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl
123123 return req
124124}
125125
126- func outputResult (p * print.Printer , model * inputModel , instanceLabel string , resp * redis.CredentialsResponse ) error {
126+ func outputResult (p * print.Printer , model inputModel , instanceLabel string , resp * redis.CredentialsResponse ) error {
127+ if model .GlobalFlagModel == nil {
128+ return fmt .Errorf ("no global flags defined" )
129+ }
130+ if resp == nil {
131+ return fmt .Errorf ("no response defined" )
132+ }
127133 if ! model .ShowPassword {
134+ if resp .Raw == nil {
135+ resp .Raw = & redis.RawCredentials {}
136+ }
137+ if resp .Raw .Credentials == nil {
138+ resp .Raw .Credentials = & redis.Credentials {}
139+ }
128140 resp .Raw .Credentials .Password = utils .Ptr ("hidden" )
129141 }
130142
@@ -146,11 +158,11 @@ func outputResult(p *print.Printer, model *inputModel, instanceLabel string, res
146158
147159 return nil
148160 default :
149- p .Outputf ("Created credentials for instance %q. Credentials ID: %s\n \n " , instanceLabel , * resp .Id )
161+ p .Outputf ("Created credentials for instance %q. Credentials ID: %s\n \n " , instanceLabel , utils . PtrString ( resp .Id ) )
150162 // The username field cannot be set by the user, so we only display it if it's not returned empty
151163 if resp .HasRaw () && resp .Raw .Credentials != nil {
152164 if username := resp .Raw .Credentials .Username ; username != nil && * username != "" {
153- p .Outputf ("Username: %s\n " , * username )
165+ p .Outputf ("Username: %s\n " , utils . PtrString ( username ) )
154166 }
155167 if ! model .ShowPassword {
156168 p .Outputf ("Password: <hidden>\n " )
0 commit comments