Don't allow non flag arguments by default.
This commit is contained in:
parent
be888b59a6
commit
31614bebc4
2 changed files with 68 additions and 4 deletions
|
@ -86,6 +86,23 @@ func Test_execute(t *testing.T) {
|
|||
},
|
||||
expected: expected{result: "root"},
|
||||
},
|
||||
{
|
||||
desc: "root command, with argument, command not found",
|
||||
args: []string{"", "echo"},
|
||||
command: func() *Command {
|
||||
return &Command{
|
||||
Name: "root",
|
||||
Description: "This is a test",
|
||||
Configuration: nil,
|
||||
Run: func(_ []string) error {
|
||||
called = "root"
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
},
|
||||
expected: expected{error: true},
|
||||
},
|
||||
{
|
||||
desc: "one sub command",
|
||||
args: []string{"", "sub1"},
|
||||
|
@ -114,6 +131,34 @@ func Test_execute(t *testing.T) {
|
|||
},
|
||||
expected: expected{result: "sub1"},
|
||||
},
|
||||
{
|
||||
desc: "one sub command, with argument, command not found",
|
||||
args: []string{"", "sub1", "echo"},
|
||||
command: func() *Command {
|
||||
rootCmd := &Command{
|
||||
Name: "test",
|
||||
Description: "This is a test",
|
||||
Configuration: nil,
|
||||
Run: func(_ []string) error {
|
||||
called += "root"
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
_ = rootCmd.AddCommand(&Command{
|
||||
Name: "sub1",
|
||||
Description: "sub1",
|
||||
Configuration: nil,
|
||||
Run: func(_ []string) error {
|
||||
called += "sub1"
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
return rootCmd
|
||||
},
|
||||
expected: expected{error: true},
|
||||
},
|
||||
{
|
||||
desc: "two sub commands",
|
||||
args: []string{"", "sub2"},
|
||||
|
@ -376,6 +421,7 @@ func Test_execute(t *testing.T) {
|
|||
Name: "sub1",
|
||||
Description: "sub1",
|
||||
Configuration: nil,
|
||||
AllowArg: true,
|
||||
Run: func(args []string) error {
|
||||
called += "sub1-" + strings.Join(args, "-")
|
||||
return nil
|
||||
|
@ -394,6 +440,7 @@ func Test_execute(t *testing.T) {
|
|||
Name: "root",
|
||||
Description: "This is a test",
|
||||
Configuration: nil,
|
||||
AllowArg: true,
|
||||
Run: func(args []string) error {
|
||||
called += "root-" + strings.Join(args, "-")
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue