Skip to content

Commit

Permalink
fix(cli) stores list if no stores are returned, call that out.
Browse files Browse the repository at this point in the history
Signed-off-by: sbailey <1661003+spbsoluble@users.noreply.github.com>
  • Loading branch information
spbsoluble committed Aug 26, 2024
1 parent ab0cc59 commit 4501be8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ func outputResult(result interface{}, format string) {
}

if format == "json" {
if jerr != nil {
output = fmt.Sprintf("{\"message\": \"%s\"}", result)
fmt.Println(output)
return
}
jsonOutput, err := json.MarshalIndent(output, "", " ")
if err != nil {
//then output a { "message": "result" } json
Expand Down
16 changes: 14 additions & 2 deletions cmd/stores.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"encoding/csv"
"encoding/json"
"fmt"
"os"

"github.com/AlecAivazis/survey/v2"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"os"
)

// storesCmd represents the stores command
Expand Down Expand Up @@ -61,6 +62,11 @@ var storesListCmd = &cobra.Command{
log.Error().Err(err).Send()
return err
}
if stores == nil || *stores == nil {
log.Info().Msg("No certificate stores found")
outputResult("No certificate stores found", outputFormat)
return nil
}
output, jErr := json.Marshal(stores)
if jErr != nil {
log.Error().Err(jErr).Send()
Expand Down Expand Up @@ -298,7 +304,13 @@ func init() {

// delete cmd
storesDeleteCmd.Flags().StringVarP(&storeID, "id", "i", "", "ID of the certificate store to delete.")
storesDeleteCmd.Flags().StringVarP(&inputFile, "file", "f", "", "The path to a CSV file containing the Ids of the stores to delete.")
storesDeleteCmd.Flags().StringVarP(
&inputFile,
"file",
"f",
"",
"The path to a CSV file containing the Ids of the stores to delete.",
)
storesDeleteCmd.Flags().BoolVarP(&deleteAll, "all", "a", false, "Attempt to delete ALL stores.")
storesDeleteCmd.MarkFlagsMutuallyExclusive("id", "all")

Expand Down

0 comments on commit 4501be8

Please sign in to comment.