mirror of
https://github.com/spf13/cobra.git
synced 2024-11-15 17:58:18 -07:00
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:
commit
6264dc67e1
@ -275,6 +275,7 @@ func stripFlags(args []string, c *Command) []string {
|
||||
if len(args) < 1 {
|
||||
return args
|
||||
}
|
||||
c.mergePersistentFlags()
|
||||
|
||||
commands := []string{}
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user