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)
|
2015-10-03 15:19:04 +00:00
|
|
|
test := []string{"blah", "blah", "-break"}
|
2014-04-14 21:44:32 +00:00
|
|
|
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)
|
|
|
|
}
|
2015-09-25 21:13:36 +00:00
|
|
|
|
|
|
|
// Fix bug with ignoring flag parsing that would still parse the first flag
|
|
|
|
func TestCommandIgnoreFlagsIncludingFirstArgument(t *testing.T) {
|
|
|
|
app := NewApp()
|
|
|
|
set := flag.NewFlagSet("test", 0)
|
|
|
|
test := []string{"blah", "-break"}
|
|
|
|
set.Parse(test)
|
|
|
|
|
|
|
|
c := NewContext(app, set, nil)
|
|
|
|
|
|
|
|
command := Command{
|
|
|
|
Name: "test-cmd",
|
|
|
|
Aliases: []string{"tc"},
|
|
|
|
Usage: "this is for testing",
|
|
|
|
Description: "testing",
|
|
|
|
Action: func(_ *Context) {},
|
|
|
|
SkipFlagParsing: true,
|
|
|
|
}
|
|
|
|
err := command.Run(c)
|
|
|
|
|
|
|
|
expect(t, err, nil)
|
|
|
|
}
|