Skip to content

Commit 4501be8

Browse files
committed
fix(cli) stores list if no stores are returned, call that out.
Signed-off-by: sbailey <1661003+spbsoluble@users.noreply.github.com>
1 parent ab0cc59 commit 4501be8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

cmd/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ func outputResult(result interface{}, format string) {
339339
}
340340

341341
if format == "json" {
342+
if jerr != nil {
343+
output = fmt.Sprintf("{\"message\": \"%s\"}", result)
344+
fmt.Println(output)
345+
return
346+
}
342347
jsonOutput, err := json.MarshalIndent(output, "", " ")
343348
if err != nil {
344349
//then output a { "message": "result" } json

cmd/stores.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ import (
1818
"encoding/csv"
1919
"encoding/json"
2020
"fmt"
21+
"os"
22+
2123
"github.com/AlecAivazis/survey/v2"
2224
"github.com/rs/zerolog/log"
2325
"github.com/spf13/cobra"
24-
"os"
2526
)
2627

2728
// storesCmd represents the stores command
@@ -61,6 +62,11 @@ var storesListCmd = &cobra.Command{
6162
log.Error().Err(err).Send()
6263
return err
6364
}
65+
if stores == nil || *stores == nil {
66+
log.Info().Msg("No certificate stores found")
67+
outputResult("No certificate stores found", outputFormat)
68+
return nil
69+
}
6470
output, jErr := json.Marshal(stores)
6571
if jErr != nil {
6672
log.Error().Err(jErr).Send()
@@ -298,7 +304,13 @@ func init() {
298304

299305
// delete cmd
300306
storesDeleteCmd.Flags().StringVarP(&storeID, "id", "i", "", "ID of the certificate store to delete.")
301-
storesDeleteCmd.Flags().StringVarP(&inputFile, "file", "f", "", "The path to a CSV file containing the Ids of the stores to delete.")
307+
storesDeleteCmd.Flags().StringVarP(
308+
&inputFile,
309+
"file",
310+
"f",
311+
"",
312+
"The path to a CSV file containing the Ids of the stores to delete.",
313+
)
302314
storesDeleteCmd.Flags().BoolVarP(&deleteAll, "all", "a", false, "Attempt to delete ALL stores.")
303315
storesDeleteCmd.MarkFlagsMutuallyExclusive("id", "all")
304316

0 commit comments

Comments
 (0)