@@ -110,6 +110,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
110110}
111111
112112func outputResult (p * print.Printer , outputFormat string , showOnlyPublicKey bool , keyPair * iaas.Keypair ) error {
113+ if keyPair == nil {
114+ p .Outputln ("No keypair found." )
115+ return nil
116+ }
113117 switch outputFormat {
114118 case print .JSONOutputFormat :
115119 details , err := json .MarshalIndent (keyPair , "" , " " )
@@ -150,7 +154,7 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool,
150154 table .AddRow ("KEY PAIR NAME" , utils .PtrString (keyPair .Name ))
151155 table .AddSeparator ()
152156
153- if * keyPair .Labels != nil && len (* keyPair .Labels ) > 0 {
157+ if keyPair .Labels != nil && len (* keyPair .Labels ) > 0 {
154158 var labels []string
155159 for key , value := range * keyPair .Labels {
156160 labels = append (labels , fmt .Sprintf ("%s: %s" , key , value ))
@@ -162,7 +166,11 @@ func outputResult(p *print.Printer, outputFormat string, showOnlyPublicKey bool,
162166 table .AddRow ("FINGERPRINT" , utils .PtrString (keyPair .Fingerprint ))
163167 table .AddSeparator ()
164168
165- truncatedPublicKey := (* keyPair .PublicKey )[:maxLengthPublicKey ] + "..."
169+ truncatedPublicKey := ""
170+ if keyPair .PublicKey != nil {
171+ truncatedPublicKey = (* keyPair .PublicKey )[:maxLengthPublicKey ] + "..."
172+ }
173+
166174 table .AddRow ("PUBLIC KEY" , truncatedPublicKey )
167175 table .AddSeparator ()
168176
0 commit comments