c538c376c9
Signed-off-by: Nathan LeClaire <nathan.leclaire@gmail.com>
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"flag"
|
|
"testing"
|
|
)
|
|
|
|
func TestCommandDoNotIgnoreFlags(t *testing.T) {
|
|
app := NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
test := []string{"blah", "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) {},
|
|
}
|
|
err := command.Run(c)
|
|
|
|
expect(t, err.Error(), "flag provided but not defined: -break")
|
|
}
|
|
|
|
func TestCommandIgnoreFlags(t *testing.T) {
|
|
app := NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
test := []string{"blah", "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)
|
|
}
|
|
|
|
// 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)
|
|
}
|