forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#4555: Move client/{tx,rest,utils} into x/auth/client
- Loading branch information
1 parent
941effc
commit 73700df
Showing
51 changed files
with
620 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#4488 Decouple client tx, REST, and ultil packages from auth. These packages have | ||
been restructured and retrofitted into the `x/auth` module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ValidateCmd returns unknown command error or Help display if help flag set | ||
func ValidateCmd(cmd *cobra.Command, args []string) error { | ||
var cmds []string | ||
var help bool | ||
|
||
// construct array of commands and search for help flag | ||
for _, arg := range args { | ||
if arg == "--help" || arg == "-h" { | ||
help = true | ||
} else if len(arg) > 0 && !(arg[0] == '-') { | ||
cmds = append(cmds, arg) | ||
} | ||
} | ||
|
||
if !help && len(cmds) > 0 { | ||
err := fmt.Sprintf("unknown command \"%s\" for \"%s\"", cmds[0], cmd.CalledAs()) | ||
|
||
// build suggestions for unknown argument | ||
if suggestions := cmd.SuggestionsFor(cmds[0]); len(suggestions) > 0 { | ||
err += "\n\nDid you mean this?\n" | ||
for _, s := range suggestions { | ||
err += fmt.Sprintf("\t%v\n", s) | ||
} | ||
} | ||
return errors.New(err) | ||
} | ||
|
||
return cmd.Help() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package client_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
) | ||
|
||
func TestValidateCmd(t *testing.T) { | ||
// setup root and subcommands | ||
rootCmd := &cobra.Command{ | ||
Use: "root", | ||
} | ||
queryCmd := &cobra.Command{ | ||
Use: "query", | ||
} | ||
rootCmd.AddCommand(queryCmd) | ||
|
||
// command being tested | ||
distCmd := &cobra.Command{ | ||
Use: "distr", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
} | ||
queryCmd.AddCommand(distCmd) | ||
|
||
commissionCmd := &cobra.Command{ | ||
Use: "commission", | ||
} | ||
distCmd.AddCommand(commissionCmd) | ||
|
||
tests := []struct { | ||
reason string | ||
args []string | ||
wantErr bool | ||
}{ | ||
{"misspelled command", []string{"comission"}, true}, | ||
{"no command provided", []string{}, false}, | ||
{"help flag", []string{"comission", "--help"}, false}, | ||
{"shorthand help flag", []string{"comission", "-h"}, false}, | ||
} | ||
|
||
for _, tt := range tests { | ||
err := client.ValidateCmd(distCmd, tt.args) | ||
require.Equal(t, tt.wantErr, err != nil, tt.reason) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.