From 93278e2f35a3369164c791436315f1f97639d980 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Mon, 16 Mar 2015 12:47:32 -0700 Subject: [PATCH] Add mergePersistentFlags in strip flags since we now look at the flag set. --- command.go | 1 + command_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/command.go b/command.go index 82368e2..7285d10 100644 --- a/command.go +++ b/command.go @@ -275,6 +275,7 @@ func stripFlags(args []string, c *Command) []string { if len(args) < 1 { return args } + c.mergePersistentFlags() commands := []string{} diff --git a/command_test.go b/command_test.go index ae66522..308f7fd 100644 --- a/command_test.go +++ b/command_test.go @@ -5,6 +5,8 @@ import ( "testing" ) +// TODO Test persistent flags on subcommands. This requires testing the full execute function. + func TestStripFlags(t *testing.T) { tests := []struct { input []string @@ -54,6 +56,14 @@ func TestStripFlags(t *testing.T) { []string{"-c", "bar", "-i", "foo", "blah"}, []string{"bar", "blah"}, }, + { + []string{"--persist", "bar"}, + []string{"bar"}, + }, + { + []string{"-p", "bar"}, + []string{"bar"}, + }, } cmdPrint := &Command{ @@ -68,6 +78,7 @@ func TestStripFlags(t *testing.T) { var flagi int var flagstr string 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().StringVarP(&flagstr, "bar", "b", "bar", "help message for flag string") cmdPrint.Flags().BoolVarP(&flagbool, "cat", "c", false, "help message for flag bool")