Skip to content

Commit

Permalink
output flag to format json
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jun 26, 2024
1 parent c5bc58e commit 8e2f8bb
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions server/module_hash_by_height.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"encoding/hex"
"encoding/json"
"fmt"
"path/filepath"
"sort"
Expand All @@ -14,6 +15,7 @@ import (
"cosmossdk.io/store/rootmulti"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/client/flags"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
)

Expand Down Expand Up @@ -42,13 +44,32 @@ Example:
return err
}

// Print the CommitInfo to the console.
fmt.Println(commitInfoForHeight.String())
// Get the output format flag
outputFormat, err := cmd.Flags().GetString(flags.FlagOutput)
if err != nil {
return err
}

// Print the CommitInfo based on the output format
switch outputFormat {
case flags.OutputFormatJSON:
jsonOutput, err := json.MarshalIndent(commitInfoForHeight, "", " ")
if err != nil {
return err
}
fmt.Println(string(jsonOutput))
case flags.OutputFormatText:
fallthrough
default:
fmt.Println(commitInfoForHeight.String())
}

return nil
},
}

cmd.Flags().StringP(flags.FlagOutput, "o", flags.OutputFormatText, "Output format (text|json)")

return cmd
}

Expand Down

0 comments on commit 8e2f8bb

Please sign in to comment.