|
|
|
@ -13,12 +13,18 @@ func TestCommandFlagParsing(t *testing.T) {
|
|
|
|
|
cases := []struct {
|
|
|
|
|
testArgs []string
|
|
|
|
|
skipFlagParsing bool
|
|
|
|
|
skipArgReorder bool
|
|
|
|
|
expectedErr error
|
|
|
|
|
}{
|
|
|
|
|
{[]string{"blah", "blah", "-break"}, false, errors.New("flag provided but not defined: -break")}, // Test normal "not ignoring flags" flow
|
|
|
|
|
{[]string{"blah", "blah"}, true, nil}, // Test SkipFlagParsing without any args that look like flags
|
|
|
|
|
{[]string{"blah", "-break"}, true, nil}, // Test SkipFlagParsing with random flag arg
|
|
|
|
|
{[]string{"blah", "-help"}, true, nil}, // Test SkipFlagParsing with "special" help flag arg
|
|
|
|
|
// Test normal "not ignoring flags" flow
|
|
|
|
|
{[]string{"test-cmd", "blah", "blah", "-break"}, false, false, errors.New("flag provided but not defined: -break")},
|
|
|
|
|
|
|
|
|
|
// Test no arg reorder
|
|
|
|
|
{[]string{"test-cmd", "blah", "blah", "-break"}, false, true, nil},
|
|
|
|
|
|
|
|
|
|
{[]string{"test-cmd", "blah", "blah"}, true, false, nil}, // Test SkipFlagParsing without any args that look like flags
|
|
|
|
|
{[]string{"test-cmd", "blah", "-break"}, true, false, nil}, // Test SkipFlagParsing with random flag arg
|
|
|
|
|
{[]string{"test-cmd", "blah", "-help"}, true, false, nil}, // Test SkipFlagParsing with "special" help flag arg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
@ -30,15 +36,15 @@ func TestCommandFlagParsing(t *testing.T) {
|
|
|
|
|
context := NewContext(app, set, nil)
|
|
|
|
|
|
|
|
|
|
command := Command{
|
|
|
|
|
Name: "test-cmd",
|
|
|
|
|
Aliases: []string{"tc"},
|
|
|
|
|
Usage: "this is for testing",
|
|
|
|
|
Description: "testing",
|
|
|
|
|
Action: func(_ *Context) error { return nil },
|
|
|
|
|
Name: "test-cmd",
|
|
|
|
|
Aliases: []string{"tc"},
|
|
|
|
|
Usage: "this is for testing",
|
|
|
|
|
Description: "testing",
|
|
|
|
|
Action: func(_ *Context) error { return nil },
|
|
|
|
|
SkipFlagParsing: c.skipFlagParsing,
|
|
|
|
|
SkipArgReorder: c.skipArgReorder,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command.SkipFlagParsing = c.skipFlagParsing
|
|
|
|
|
|
|
|
|
|
err := command.Run(context)
|
|
|
|
|
|
|
|
|
|
expect(t, err, c.expectedErr)
|
|
|
|
|