Skip to content
Myr

Merge pull request #70 from brendandburns/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add mergePersistentFlags in strip flags since we now look at the flag set.

authored by Bjørn Erik Pedersen · committed by Bjørn Erik Pedersen · parents 9e7273d, 93278e2 · Browse files · 2 files+12 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−0 removed

  • other:+12 added−0 removed

2 files+12 added−0 removed

modified:command_test.go+11 added
3 unmodified lines
4 "reflect"5 "testing"6)78// TODO Test persistent flags on subcommands. This requires testing the full execute function.910func TestStripFlags(t *testing.T) {11 tests := []struct {12 input []string13 output []string
41 unmodified lines
55 {56 []string{"-c", "bar", "-i", "foo", "blah"},57 []string{"bar", "blah"},58 },59 {60 []string{"--persist", "bar"},61 []string{"bar"},62 },63 {64 []string{"-p", "bar"},65 []string{"bar"},66 },67 }6869 cmdPrint := &Command{70 Use: "print [string to print]",
6 unmodified lines
7778 var flagi int79 var flagstr string80 var flagbool bool81 cmdPrint.PersistentFlags().BoolVarP(&flagbool, "persist", "p", false, "help for persistent one")82 cmdPrint.Flags().IntVarP(&flagi, "int", "i", 345, "help message for flag int")83 cmdPrint.Flags().StringVarP(&flagstr, "bar", "b", "bar", "help message for flag string")84 cmdPrint.Flags().BoolVarP(&flagbool, "cat", "c", false, "help message for flag bool")85
7 unmodified lines
modified:command.go+1 added
273 unmodified lines
274func stripFlags(args []string, c *Command) []string {275 if len(args) < 1 {276 return args277 }278 c.mergePersistentFlags()279280 commands := []string{}281282 inQuote := false
666 unmodified lines