Merge pull request #70 from brendandburns/master

Add mergePersistentFlags in strip flags since we now look at the flag set.
This commit is contained in:
Bjørn Erik Pedersen 2015-03-17 00:30:08 +01:00
commit 6264dc67e1
2 changed files with 12 additions and 0 deletions

View file

@ -275,6 +275,7 @@ func stripFlags(args []string, c *Command) []string {
if len(args) < 1 { if len(args) < 1 {
return args return args
} }
c.mergePersistentFlags()
commands := []string{} commands := []string{}

View file

@ -5,6 +5,8 @@ import (
"testing" "testing"
) )
// TODO Test persistent flags on subcommands. This requires testing the full execute function.
func TestStripFlags(t *testing.T) { func TestStripFlags(t *testing.T) {
tests := []struct { tests := []struct {
input []string input []string
@ -54,6 +56,14 @@ func TestStripFlags(t *testing.T) {
[]string{"-c", "bar", "-i", "foo", "blah"}, []string{"-c", "bar", "-i", "foo", "blah"},
[]string{"bar", "blah"}, []string{"bar", "blah"},
}, },
{
[]string{"--persist", "bar"},
[]string{"bar"},
},
{
[]string{"-p", "bar"},
[]string{"bar"},
},
} }
cmdPrint := &Command{ cmdPrint := &Command{
@ -68,6 +78,7 @@ func TestStripFlags(t *testing.T) {
var flagi int var flagi int
var flagstr string var flagstr string
var flagbool bool var flagbool bool
cmdPrint.PersistentFlags().BoolVarP(&flagbool, "persist", "p", false, "help for persistent one")
cmdPrint.Flags().IntVarP(&flagi, "int", "i", 345, "help message for flag int") cmdPrint.Flags().IntVarP(&flagi, "int", "i", 345, "help message for flag int")
cmdPrint.Flags().StringVarP(&flagstr, "bar", "b", "bar", "help message for flag string") cmdPrint.Flags().StringVarP(&flagstr, "bar", "b", "bar", "help message for flag string")
cmdPrint.Flags().BoolVarP(&flagbool, "cat", "c", false, "help message for flag bool") cmdPrint.Flags().BoolVarP(&flagbool, "cat", "c", false, "help message for flag bool")