Skip to content

Commit

Permalink
set option for json output
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored and Pantani committed Dec 16, 2023
1 parent a5f88d4 commit 5ccd3d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions hermes/cmd/hermes_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func hermesConfigureHandler(cmd *cobra.Command, args []string) error {
chainBID,
hermes.WithConfigFile(cfgPath),
hermes.WithStdOut(&bufClientAResult),
hermes.WithJSONOutput(),
); err != nil {
return err
}
Expand All @@ -305,6 +306,7 @@ func hermesConfigureHandler(cmd *cobra.Command, args []string) error {
chainAID,
hermes.WithConfigFile(cfgPath),
hermes.WithStdOut(&bufClientBResult),
hermes.WithJSONOutput(),
); err != nil {
return err
}
Expand Down Expand Up @@ -332,6 +334,7 @@ func hermesConfigureHandler(cmd *cobra.Command, args []string) error {
clientBResult.CreateClient.ClientID,
hermes.WithConfigFile(cfgPath),
hermes.WithStdOut(&bufConnection),
hermes.WithJSONOutput(),
); err != nil {
return err
}
Expand Down Expand Up @@ -361,6 +364,7 @@ func hermesConfigureHandler(cmd *cobra.Command, args []string) error {
chainBPortID,
hermes.WithConfigFile(cfgPath),
hermes.WithStdOut(&bufChannel),
hermes.WithJSONOutput(),
); err != nil {
return err
}
Expand Down Expand Up @@ -427,6 +431,7 @@ GetKey:
chainID,
hermes.WithConfigFile(cfgPath),
hermes.WithStdOut(&bufKeysChain),
hermes.WithJSONOutput(),
); err != nil {
return "", err
}
Expand Down Expand Up @@ -474,6 +479,7 @@ GetKey:
mnemonic,
hermes.WithConfigFile(cfgPath),
hermes.WithStdOut(&bufKeysChainAdd),
hermes.WithJSONOutput(),
); err != nil {
return "", err
}
Expand Down
24 changes: 17 additions & 7 deletions hermes/pkg/hermes/hermes.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ type (

// configs holds Generate configs.
configs struct {
flags Flags
config string
args []string
stdin io.Reader
stdout io.Writer
stderr io.Writer
flags Flags
config string
args []string
stdin io.Reader
stdout io.Writer
stderr io.Writer
jsonOutput bool
}
)

Expand Down Expand Up @@ -207,6 +208,13 @@ func WithStdIn(stdin io.Reader) Option {
}
}

// WithJSONOutput add a json output.
func WithJSONOutput() Option {
return func(c *configs) {
c.jsonOutput = true
}
}

// WithStdOut add a std output.
func WithStdOut(stdout io.Writer) Option {
return func(c *configs) {
Expand Down Expand Up @@ -391,7 +399,9 @@ func (h *Hermes) Run(ctx context.Context, options ...Option) error {
if c.config != "" {
cmd = append(cmd, fmt.Sprintf("--%s=%s", FlagConfig, c.config))
}
cmd = append(cmd, "--json")
if c.jsonOutput {
cmd = append(cmd, "--json")
}
cmd = append(cmd, c.args...)

for flag, value := range c.flags {
Expand Down

0 comments on commit 5ccd3d9

Please sign in to comment.