added a flag to disable flags

This commit is contained in:
Mark Bates
2016-06-03 20:25:52 -04:00
parent f368244301
commit dc6e9ece6f
2 changed files with 31 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package cobra
import (
"os"
"reflect"
"testing"
)
@ -112,3 +113,23 @@ func TestStripFlags(t *testing.T) {
}
}
}
func Test_DisableFlagParsing(t *testing.T) {
as := []string{"-v", "-race", "-file", "foo.go"}
targs := []string{}
cmdPrint := &Command{
DisableFlagParsing: true,
Run: func(cmd *Command, args []string) {
targs = args
},
}
osargs := []string{"cmd"}
os.Args = append(osargs, as...)
err := cmdPrint.Execute()
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(as, targs) {
t.Errorf("expected: %v, got: %v", as, targs)
}
}