Skip to content

Commit

Permalink
feat: put hermes under root cmd (#82)
Browse files Browse the repository at this point in the history
* put hermes under root cmd

* add hermes under relayer command

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored Apr 17, 2024
1 parent bdb2423 commit 2d86712
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
21 changes: 16 additions & 5 deletions hermes/cmd/hermes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@ const (
flagConfig = "config"
)

// NewRelayer creates a new Relayer command that holds
func NewRelayer() *cobra.Command {
root := &cobra.Command{
Use: "relayer [command]",
Aliases: []string{"r"},
Short: "Connect blockchains with an IBC relayer",
SilenceUsage: true,
SilenceErrors: true,
}
root.AddCommand(NewHermes())
return root
}

// NewHermes creates a new Hermes relayer command that holds
// some other sub commands related to hermes relayer.
func NewHermes() *cobra.Command {
c := &cobra.Command{
Use: "hermes [command]",
Aliases: []string{"h"},
Short: "Hermes relayer wrapper",
SilenceUsage: true,
SilenceErrors: true,
Use: "hermes [command]",
Aliases: []string{"h"},
Short: "Hermes relayer wrapper",
}

// configure flags.
Expand Down
14 changes: 8 additions & 6 deletions hermes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ type app struct{}

func (app) Manifest(context.Context) (*plugin.Manifest, error) {
m := &plugin.Manifest{Name: "hermes"}
m.ImportCobraCommand(cmd.NewHermes(), "ignite relayer")
m.ImportCobraCommand(cmd.NewRelayer(), "ignite")
return m, nil
}

func (app) Execute(_ context.Context, c *plugin.ExecutedCommand, _ plugin.ClientAPI) error {
// Run the "hermes" command as if it were a root command. To do
// so remove the first two arguments which are "ignite relayer"
// from OSArgs to treat "hermes" as the root command.
os.Args = c.OsArgs[2:]
return cmd.NewHermes().Execute()
// Instead of a switch on c.Use, we run the root command like if
// we were in a command line context. This implies to set os.Args
// correctly.
// Remove the first arg "ignite" from OsArgs because our hermes
// command root is "relayer" not "ignite".
os.Args = c.OsArgs[1:]
return cmd.NewRelayer().Execute()
}

func (app) ExecuteHookPre(context.Context, *plugin.ExecutedHook, plugin.ClientAPI) error {
Expand Down
2 changes: 1 addition & 1 deletion tools/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {

// Add apps with cobra commands.
rootCmd.AddCommand(
hermes.NewHermes(),
hermes.NewRelayer(),
marketplace.NewMarketplace(),
wasm.NewWasm(),
// Add cobra commands for debugging here.
Expand Down

0 comments on commit 2d86712

Please sign in to comment.