urfave-cli/command_test.go

48 lines
979 B
Go
Raw Normal View History

package cli
2014-04-14 21:44:32 +00:00
import (
2014-06-18 05:33:30 +00:00
"flag"
2014-04-14 21:44:32 +00:00
"testing"
)
func TestCommandDoNotIgnoreFlags(t *testing.T) {
app := NewApp()
2014-04-14 21:44:32 +00:00
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah", "-break"}
set.Parse(test)
c := NewContext(app, set, nil)
2014-04-14 21:44:32 +00:00
command := Command{
2014-06-18 05:33:30 +00:00
Name: "test-cmd",
Aliases: []string{"tc"},
2014-06-18 05:33:30 +00:00
Usage: "this is for testing",
2014-04-14 21:44:32 +00:00
Description: "testing",
Action: func(_ *Context) {},
2014-04-14 21:44:32 +00:00
}
err := command.Run(c)
expect(t, err.Error(), "flag provided but not defined: -break")
}
func TestCommandIgnoreFlags(t *testing.T) {
app := NewApp()
2014-04-14 21:44:32 +00:00
set := flag.NewFlagSet("test", 0)
test := []string{"blah", "blah", "-break"}
2014-04-14 21:44:32 +00:00
set.Parse(test)
c := NewContext(app, set, nil)
2014-04-14 21:44:32 +00:00
command := Command{
2014-06-18 05:33:30 +00:00
Name: "test-cmd",
Aliases: []string{"tc"},
2014-06-18 05:33:30 +00:00
Usage: "this is for testing",
Description: "testing",
Action: func(_ *Context) {},
2014-04-14 21:44:32 +00:00
SkipFlagParsing: true,
}
err := command.Run(c)
expect(t, err, nil)
}