Add SkipFlagParsing option to Command

This commit is contained in:
Dan Wendorf and Karen Wang
2014-04-14 14:44:32 -07:00
parent 640826c88f
commit 6c5f810d8f
2 changed files with 51 additions and 1 deletions

48
command_test.go Normal file
View File

@@ -0,0 +1,48 @@
package cli_test
import (
"flag"
"github.com/codegangsta/cli"
"testing"
)
func TestCommandDoNotIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah", "-break"}
set.Parse(test)
c := cli.NewContext(app, set, set)
command := cli.Command {
Name: "test-cmd",
ShortName: "tc",
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) { },
}
err := command.Run(c)
expect(t, err.Error(), "flag provided but not defined: -break")
}
func TestCommandIgnoreFlags(t *testing.T) {
app := cli.NewApp()
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah"}
set.Parse(test)
c := cli.NewContext(app, set, set)
command := cli.Command {
Name: "test-cmd",
ShortName: "tc",
Usage: "this is for testing",
Description: "testing",
Action: func(_ *cli.Context) { },
SkipFlagParsing: true,
}
err := command.Run(c)
expect(t, err, nil)
}