2015-07-20 19:18:25 +00:00
|
|
|
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) {
|
2015-07-20 19:18:25 +00:00
|
|
|
app := NewApp()
|
2014-04-14 21:44:32 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
test := []string{"blah", "blah", "-break"}
|
|
|
|
set.Parse(test)
|
|
|
|
|
2015-07-20 19:18:25 +00:00
|
|
|
c := NewContext(app, set, nil)
|
2014-04-14 21:44:32 +00:00
|
|
|
|
2015-07-20 19:18:25 +00:00
|
|
|
command := Command{
|
2014-06-18 05:33:30 +00:00
|
|
|
Name: "test-cmd",
|
2015-03-10 04:24:57 +00:00
|
|
|
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",
|
2015-07-20 19:18:25 +00:00
|
|
|
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) {
|
2015-07-20 19:18:25 +00:00
|
|
|
app := NewApp()
|
2014-04-14 21:44:32 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
test := []string{"blah", "blah"}
|
|
|
|
set.Parse(test)
|
|
|
|
|
2015-07-20 19:18:25 +00:00
|
|
|
c := NewContext(app, set, nil)
|
2014-04-14 21:44:32 +00:00
|
|
|
|
2015-07-20 19:18:25 +00:00
|
|
|
command := Command{
|
2014-06-18 05:33:30 +00:00
|
|
|
Name: "test-cmd",
|
2015-03-10 04:24:57 +00:00
|
|
|
Aliases: []string{"tc"},
|
2014-06-18 05:33:30 +00:00
|
|
|
Usage: "this is for testing",
|
|
|
|
Description: "testing",
|
2015-07-20 19:18:25 +00:00
|
|
|
Action: func(_ *Context) {},
|
2014-04-14 21:44:32 +00:00
|
|
|
SkipFlagParsing: true,
|
|
|
|
}
|
|
|
|
err := command.Run(c)
|
|
|
|
|
|
|
|
expect(t, err, nil)
|
|
|
|
}
|