Skip to content

Commit

Permalink
Merge pull request #104 from dongrie/cmd-exit
Browse files Browse the repository at this point in the history
Return an error when an invalid command is specified
  • Loading branch information
siburu authored Sep 6, 2023
2 parents 84716e7 + 62c0637 commit 4e6ebe3
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"

Expand All @@ -18,6 +17,7 @@ func chainsCmd(ctx *config.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "chains",
Short: "manage chain configurations",
RunE: noCommand,
}

cmd.AddCommand(
Expand Down Expand Up @@ -46,7 +46,7 @@ func chainsAddDirCmd(ctx *config.Context) *cobra.Command {

func filesAdd(ctx *config.Context, dir string) error {
dir = path.Clean(dir)
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return err
}
Expand All @@ -56,7 +56,7 @@ func filesAdd(ctx *config.Context, dir string) error {
fmt.Printf("directory at %s, skipping...\n", pth)
continue
}
byt, err := ioutil.ReadFile(pth)
byt, err := os.ReadFile(pth)
if err != nil {
fmt.Printf("failed to read file %s, skipping...\n", pth)
continue
Expand Down Expand Up @@ -105,7 +105,7 @@ func overWriteConfig(ctx *config.Context, cmd *cobra.Command) error {
}

// overwrite the config file
err = ioutil.WriteFile(viper.ConfigFileUsed(), out, 0600)
err = os.WriteFile(viper.ConfigFileUsed(), out, 0600)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func configCmd(ctx *config.Context) *cobra.Command {
Use: "config",
Aliases: []string{"cfg"},
Short: "manage configuration file",
RunE: noCommand,
}

cmd.AddCommand(
Expand Down
1 change: 1 addition & 0 deletions cmd/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func modulesCmd(ctx *config.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "modules",
Short: "show an info about Relayer Module",
RunE: noCommand,
}

cmd.AddCommand(
Expand Down
1 change: 1 addition & 0 deletions cmd/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func pathsCmd(ctx *config.Context) *cobra.Command {
Long: `
A path represents the "full path" or "link" for communication between two chains. This includes the client,
connection, and channel ids from both the source and destination chains as well as the strategy to use when relaying`,
RunE: noCommand,
}

cmd.AddCommand(
Expand Down
1 change: 1 addition & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func queryCmd(ctx *config.Context) *cobra.Command {
Use: "query",
Short: "IBC Query Commands",
Long: "Commands to query IBC primitives, and other useful data on configured chains.",
RunE: noCommand,
}

cmd.AddCommand(
Expand Down
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bufio"
"errors"
"fmt"
"os"
"strings"
Expand All @@ -28,6 +29,7 @@ func Execute(modules ...config.ModuleI) error {
var rootCmd = &cobra.Command{
Use: "yrly",
Short: "This application relays data between configured IBC enabled chains",
RunE: noCommand,
}

cobra.EnableCommandSorting = false
Expand Down Expand Up @@ -98,3 +100,8 @@ func readStdin() (string, error) {
str, err := bufio.NewReader(os.Stdin).ReadString('\n')
return strings.TrimSpace(str), err
}

func noCommand(cmd *cobra.Command, args []string) error {
cmd.Help()
return errors.New("specified command does not exist")
}
1 change: 1 addition & 0 deletions cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func serviceCmd(ctx *config.Context) *cobra.Command {
Use: "service",
Short: "Relay Service Commands",
Long: "Commands to manage the relay service",
RunE: noCommand,
}
cmd.AddCommand(
startCmd(ctx),
Expand Down
1 change: 1 addition & 0 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func transactionCmd(ctx *config.Context) *cobra.Command {
Most of these commands take a '[path]' argument. Make sure:
1. Chains are properly configured to relay over by using the 'rly chains list' command
2. Path is properly configured to relay over by using the 'rly paths list' command`),
RunE: noCommand,
}

cmd.AddCommand(
Expand Down
4 changes: 0 additions & 4 deletions tests/cases/tm2tm/scripts/handshake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ PATH_NAME=ibc01
$RLY tendermint keys show $CHAINID_ONE $RLYKEY
$RLY tendermint keys show $CHAINID_TWO $RLYKEY

# configure the chain to use that key by default
$RLY chains edit $CHAINID_ONE key $RLYKEY
$RLY chains edit $CHAINID_TWO key $RLYKEY

# initialize the light client for {{chain_id}}
retry 5 $RLY tendermint light init $CHAINID_ONE -f
retry 5 $RLY tendermint light init $CHAINID_TWO -f
Expand Down
4 changes: 0 additions & 4 deletions tests/cases/tmmock2tmmock/scripts/handshake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ PATH_NAME=ibc01
$RLY tendermint keys show $CHAINID_ONE $RLYKEY
$RLY tendermint keys show $CHAINID_TWO $RLYKEY

# configure the chain to use that key by default
$RLY chains edit $CHAINID_ONE key $RLYKEY
$RLY chains edit $CHAINID_TWO key $RLYKEY

# add a path between chain0 and chain1
$RLY paths add $CHAINID_ONE $CHAINID_TWO $PATH_NAME --file=./configs/path.json

Expand Down

0 comments on commit 4e6ebe3

Please sign in to comment.