From 8bff6aff17f3e1b541c2ab377e7a8aa8d2997431 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Wed, 19 Jul 2023 00:35:39 +0900 Subject: [PATCH 01/10] add new flag to lflags --- command.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index 01f7c6f1..54158f1e 100644 --- a/command.go +++ b/command.go @@ -1633,7 +1633,10 @@ func (c *Command) LocalFlags() *flag.FlagSet { addToLocal := func(f *flag.Flag) { // Add the flag if it is not a parent PFlag, or it shadows a parent PFlag if c.lflags.Lookup(f.Name) == nil && f != c.parentsPflags.Lookup(f.Name) { - c.lflags.AddFlag(f) + newFlag := &flag.Flag{} + *newFlag = *f + newFlag.Changed = false + c.lflags.AddFlag(newFlag) } } c.Flags().VisitAll(addToLocal) From 55ff048a8d5ccce442051bbadf5387c47b61f789 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Wed, 19 Jul 2023 00:35:51 +0900 Subject: [PATCH 02/10] parse local flags --- command.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/command.go b/command.go index 54158f1e..a683acd6 100644 --- a/command.go +++ b/command.go @@ -1782,12 +1782,20 @@ func (c *Command) ParseFlags(args []string) error { // do it here after merging all flags and just before parse c.Flags().ParseErrorsWhitelist = flag.ParseErrorsWhitelist(c.FParseErrWhitelist) + // parse Flags err := c.Flags().Parse(args) // Print warnings if they occurred (e.g. deprecated flag messages). if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil { c.Print(c.flagErrorBuf.String()) } + // parse Local Flags + err = c.LocalFlags().Parse(args) + // Print warnings if they occurred (e.g. deprecated flag messages). + if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil { + c.Print(c.flagErrorBuf.String()) + } + return err } From 200e51835642e161edbba724d809676d6a42040f Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 22 Jul 2023 14:55:03 +0900 Subject: [PATCH 03/10] parse lflags --- command.go | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index a683acd6..8bd403c1 100644 --- a/command.go +++ b/command.go @@ -1767,6 +1767,91 @@ func (c *Command) persistentFlag(name string) (flag *flag.Flag) { return } +func (c *Command) parseLongArgs(s string, args []string) (passedArgs, restArgs []string) { + restArgs = args + + split := strings.SplitN(s[2:], "=", 2) + name := split[0] + searchedFlag := c.lflags.Lookup(name) + + if searchedFlag == nil { + // a flag not registered in c.lflags should be registered in c.flags + c.flags.VisitAll(func(f *flag.Flag) { + if name == f.Name { + if len(split) == 1 && f.NoOptDefVal == "" && len(args) > 0 { + // '--flag arg' + restArgs = args[1:] + } + return + } + }) + } + + passedArgs = append(passedArgs, fmt.Sprintf("--%s", name)) + if len(split) == 1 && searchedFlag.NoOptDefVal == "" && len(args) > 0 { + passedArgs = append(passedArgs, args[0]) + restArgs = args[1:] + } + + return +} + +func (c *Command) parseShortArgs(s string, args []string) (passedArgs []string, restArgs []string) { + restArgs = args + + shorthands := s[1:] + shorthand := string(s[1]) + + searchedFlag := c.lflags.ShorthandLookup(shorthand) + if searchedFlag == nil { + // a flag not registered in c.lflags should be registered in c.flags + c.flags.VisitAll(func(f *flag.Flag) { + if shorthand == f.Shorthand { + if len(shorthands) == 1 && f.NoOptDefVal == "" && len(args) > 0 { + // '-f arg' + restArgs = args[1:] + } + } + }) + return + } + + passedArgs = append(passedArgs, s) + if len(shorthands) == 1 && searchedFlag.NoOptDefVal == "" && len(args) > 0 { + // '-f arg' + passedArgs = append(passedArgs, args[0]) + restArgs = args[1:] + } + + return +} + +func (c *Command) removeParentPersistentArgs(args []string) []string { + var newArgs []string + + for len(args) > 0 { + s := args[0] + args = args[1:] + if s[0] != '-' { + newArgs = append(newArgs, s) + continue + } + + var passedArgs, restArgs []string + if s[1] == '-' { + passedArgs, restArgs = c.parseLongArgs(s, args) + } else { + passedArgs, restArgs = c.parseShortArgs(s, args) + } + if len(passedArgs) > 0 { + newArgs = append(newArgs, passedArgs...) + } + args = restArgs + } + + return newArgs +} + // ParseFlags parses persistent flag tree and local flags. func (c *Command) ParseFlags(args []string) error { if c.DisableFlagParsing { @@ -1790,7 +1875,9 @@ func (c *Command) ParseFlags(args []string) error { } // parse Local Flags - err = c.LocalFlags().Parse(args) + c.LocalFlags() // need to execute LocalFlags() to set the value in c.lflags before executing removeParentPersistentArgs + localArgs := c.removeParentPersistentArgs(args) // get only arguments related to c.lflags + err = c.lflags.Parse(localArgs) // Print warnings if they occurred (e.g. deprecated flag messages). if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil { c.Print(c.flagErrorBuf.String()) From f15758ac15da01872fb8f563b5ea7808c282d8ac Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 22 Jul 2023 15:59:25 +0900 Subject: [PATCH 04/10] debug to pass command unit tests --- command.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/command.go b/command.go index 8bd403c1..bcf92473 100644 --- a/command.go +++ b/command.go @@ -1027,7 +1027,6 @@ func (c *Command) ExecuteC() (cmd *Command, err error) { c.checkCommandGroups() args := c.args - // Workaround FAIL with "go test -v" or "cobra.test -test.v", see #155 if c.args == nil && filepath.Base(os.Args[0]) != "cobra.test" { args = os.Args[1:] @@ -1769,25 +1768,30 @@ func (c *Command) persistentFlag(name string) (flag *flag.Flag) { func (c *Command) parseLongArgs(s string, args []string) (passedArgs, restArgs []string) { restArgs = args + name := s[2:] + if len(name) == 0 { + passedArgs = append(passedArgs, s) + return + } split := strings.SplitN(s[2:], "=", 2) - name := split[0] + name = split[0] searchedFlag := c.lflags.Lookup(name) if searchedFlag == nil { - // a flag not registered in c.lflags should be registered in c.flags + // ignore the flag that is not registered in c.lflags but is registered in c.flags c.flags.VisitAll(func(f *flag.Flag) { if name == f.Name { if len(split) == 1 && f.NoOptDefVal == "" && len(args) > 0 { // '--flag arg' restArgs = args[1:] } - return } }) + return } - passedArgs = append(passedArgs, fmt.Sprintf("--%s", name)) + passedArgs = append(passedArgs, fmt.Sprintf("--%s", s[2:])) if len(split) == 1 && searchedFlag.NoOptDefVal == "" && len(args) > 0 { passedArgs = append(passedArgs, args[0]) restArgs = args[1:] @@ -1804,7 +1808,7 @@ func (c *Command) parseShortArgs(s string, args []string) (passedArgs []string, searchedFlag := c.lflags.ShorthandLookup(shorthand) if searchedFlag == nil { - // a flag not registered in c.lflags should be registered in c.flags + // ignore the flag that is not registered in c.lflags but is registered in c.flags c.flags.VisitAll(func(f *flag.Flag) { if shorthand == f.Shorthand { if len(shorthands) == 1 && f.NoOptDefVal == "" && len(args) > 0 { @@ -1832,7 +1836,7 @@ func (c *Command) removeParentPersistentArgs(args []string) []string { for len(args) > 0 { s := args[0] args = args[1:] - if s[0] != '-' { + if len(s) == 0 || s[0] != '-' { newArgs = append(newArgs, s) continue } @@ -1857,7 +1861,6 @@ func (c *Command) ParseFlags(args []string) error { if c.DisableFlagParsing { return nil } - if c.flagErrorBuf == nil { c.flagErrorBuf = new(bytes.Buffer) } @@ -1873,9 +1876,13 @@ func (c *Command) ParseFlags(args []string) error { if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil { c.Print(c.flagErrorBuf.String()) } + if err != nil { + return err + } // parse Local Flags - c.LocalFlags() // need to execute LocalFlags() to set the value in c.lflags before executing removeParentPersistentArgs + c.LocalFlags() // need to execute LocalFlags() to set the value in c.lflags before executing removeParentPersistentArgs + c.lflags.ParseErrorsWhitelist = flag.ParseErrorsWhitelist(c.FParseErrWhitelist) localArgs := c.removeParentPersistentArgs(args) // get only arguments related to c.lflags err = c.lflags.Parse(localArgs) // Print warnings if they occurred (e.g. deprecated flag messages). From c67af4c687d72c41b84ca09569d47a27c8a152d0 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 22 Jul 2023 17:25:36 +0900 Subject: [PATCH 05/10] changed so that flags in c.lflags refer to flags in c.flags --- command.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/command.go b/command.go index bcf92473..5783ce7e 100644 --- a/command.go +++ b/command.go @@ -1632,10 +1632,8 @@ func (c *Command) LocalFlags() *flag.FlagSet { addToLocal := func(f *flag.Flag) { // Add the flag if it is not a parent PFlag, or it shadows a parent PFlag if c.lflags.Lookup(f.Name) == nil && f != c.parentsPflags.Lookup(f.Name) { - newFlag := &flag.Flag{} - *newFlag = *f - newFlag.Changed = false - c.lflags.AddFlag(newFlag) + f.Changed = false + c.lflags.AddFlag(f) } } c.Flags().VisitAll(addToLocal) From 99d0be84dffa23cb5b2814a123afebb476b23ee2 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 22 Jul 2023 22:57:41 +0900 Subject: [PATCH 06/10] tiny fix for removeParentPersistentArgs --- command.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/command.go b/command.go index 5783ce7e..39042751 100644 --- a/command.go +++ b/command.go @@ -1828,9 +1828,7 @@ func (c *Command) parseShortArgs(s string, args []string) (passedArgs []string, return } -func (c *Command) removeParentPersistentArgs(args []string) []string { - var newArgs []string - +func (c *Command) removeParentPersistentArgs(args []string) (newArgs []string) { for len(args) > 0 { s := args[0] args = args[1:] @@ -1850,8 +1848,7 @@ func (c *Command) removeParentPersistentArgs(args []string) []string { } args = restArgs } - - return newArgs + return } // ParseFlags parses persistent flag tree and local flags. From b51dcf624c69bf43a762a656bdf0e735b58e5fdd Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 23 Jul 2023 15:12:57 +0900 Subject: [PATCH 07/10] add lnpflags field to Command lnpflags stores localNonPersitentFlags --- command.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/command.go b/command.go index 39042751..15371289 100644 --- a/command.go +++ b/command.go @@ -150,6 +150,8 @@ type Command struct { pflags *flag.FlagSet // lflags contains local flags. lflags *flag.FlagSet + // lnpflags contains local non persistent flags + lnpflags *flag.FlagSet // iflags contains inherited flags. iflags *flag.FlagSet // parentsPflags is all persistent flags of cmd's parents. @@ -1602,15 +1604,19 @@ func (c *Command) Flags() *flag.FlagSet { // LocalNonPersistentFlags are flags specific to this command which will NOT persist to subcommands. func (c *Command) LocalNonPersistentFlags() *flag.FlagSet { - persistentFlags := c.PersistentFlags() + if c.lnpflags == nil { + persistentFlags := c.PersistentFlags() - out := flag.NewFlagSet(c.Name(), flag.ContinueOnError) - c.LocalFlags().VisitAll(func(f *flag.Flag) { - if persistentFlags.Lookup(f.Name) == nil { - out.AddFlag(f) - } - }) - return out + c.lnpflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError) + c.LocalFlags().VisitAll(func(f *flag.Flag) { + if persistentFlags.Lookup(f.Name) == nil { + f.Changed = false + c.lnpflags.AddFlag(f) + } + }) + } + + return c.lnpflags } // LocalFlags returns the local FlagSet specifically set in the current command. From 6f7d88c48cb11713849113a317fa0a35645f6483 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 23 Jul 2023 15:13:46 +0900 Subject: [PATCH 08/10] perform Parse on lnpflags --- command.go | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/command.go b/command.go index 15371289..90f98c3f 100644 --- a/command.go +++ b/command.go @@ -1770,7 +1770,7 @@ func (c *Command) persistentFlag(name string) (flag *flag.Flag) { return } -func (c *Command) parseLongArgs(s string, args []string) (passedArgs, restArgs []string) { +func (c *Command) parseLongArgs(s string, args []string, flags *flag.FlagSet) (passedArgs, restArgs []string) { restArgs = args name := s[2:] if len(name) == 0 { @@ -1780,11 +1780,10 @@ func (c *Command) parseLongArgs(s string, args []string) (passedArgs, restArgs [ split := strings.SplitN(s[2:], "=", 2) name = split[0] - searchedFlag := c.lflags.Lookup(name) - + searchedFlag := flags.Lookup(name) if searchedFlag == nil { - // ignore the flag that is not registered in c.lflags but is registered in c.flags - c.flags.VisitAll(func(f *flag.Flag) { + // ignore the flag that is not registered in passed flags but is registered in c.parentsPflags + c.parentsPflags.VisitAll(func(f *flag.Flag) { if name == f.Name { if len(split) == 1 && f.NoOptDefVal == "" && len(args) > 0 { // '--flag arg' @@ -1804,16 +1803,16 @@ func (c *Command) parseLongArgs(s string, args []string) (passedArgs, restArgs [ return } -func (c *Command) parseShortArgs(s string, args []string) (passedArgs []string, restArgs []string) { +func (c *Command) parseShortArgs(s string, args []string, flags *flag.FlagSet) (passedArgs []string, restArgs []string) { restArgs = args shorthands := s[1:] shorthand := string(s[1]) - searchedFlag := c.lflags.ShorthandLookup(shorthand) + searchedFlag := flags.ShorthandLookup(shorthand) if searchedFlag == nil { - // ignore the flag that is not registered in c.lflags but is registered in c.flags - c.flags.VisitAll(func(f *flag.Flag) { + // ignore the flag that is not registered in passed flags but is registered in c.parentsPflags + c.parentsPflags.VisitAll(func(f *flag.Flag) { if shorthand == f.Shorthand { if len(shorthands) == 1 && f.NoOptDefVal == "" && len(args) > 0 { // '-f arg' @@ -1834,7 +1833,7 @@ func (c *Command) parseShortArgs(s string, args []string) (passedArgs []string, return } -func (c *Command) removeParentPersistentArgs(args []string) (newArgs []string) { +func (c *Command) removeParentPersistentArgs(args []string, flags *flag.FlagSet) (newArgs []string) { for len(args) > 0 { s := args[0] args = args[1:] @@ -1845,9 +1844,9 @@ func (c *Command) removeParentPersistentArgs(args []string) (newArgs []string) { var passedArgs, restArgs []string if s[1] == '-' { - passedArgs, restArgs = c.parseLongArgs(s, args) + passedArgs, restArgs = c.parseLongArgs(s, args, flags) } else { - passedArgs, restArgs = c.parseShortArgs(s, args) + passedArgs, restArgs = c.parseShortArgs(s, args, flags) } if len(passedArgs) > 0 { newArgs = append(newArgs, passedArgs...) @@ -1884,12 +1883,25 @@ func (c *Command) ParseFlags(args []string) error { // parse Local Flags c.LocalFlags() // need to execute LocalFlags() to set the value in c.lflags before executing removeParentPersistentArgs c.lflags.ParseErrorsWhitelist = flag.ParseErrorsWhitelist(c.FParseErrWhitelist) - localArgs := c.removeParentPersistentArgs(args) // get only arguments related to c.lflags + localArgs := c.removeParentPersistentArgs(args, c.lflags) // get only arguments related to c.lflags err = c.lflags.Parse(localArgs) // Print warnings if they occurred (e.g. deprecated flag messages). if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil { c.Print(c.flagErrorBuf.String()) } + if err != nil { + return err + } + + // parse local non persistent flags + c.LocalNonPersistentFlags() // need to execute LocalNonPersistentFlags() to set the value in c.lnpflags before executing removeParentPersistentArgs + c.lnpflags.ParseErrorsWhitelist = flag.ParseErrorsWhitelist(c.FParseErrWhitelist) + localNonPersistentArgs := c.removeParentPersistentArgs(args, c.lnpflags) + err = c.lnpflags.Parse(localNonPersistentArgs) + // Print warnings if they occurred (e.g. deprecated flag messages). + if c.flagErrorBuf.Len()-beforeErrorBufLen > 0 && err == nil { + c.Print(c.flagErrorBuf.String()) + } return err } From eb493c9ca9b42f4524dbe19d6a3c245734cfbb71 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 23 Jul 2023 15:37:05 +0900 Subject: [PATCH 09/10] add unit tests --- command_test.go | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/command_test.go b/command_test.go index 0212f5ae..9a25ba9c 100644 --- a/command_test.go +++ b/command_test.go @@ -2735,3 +2735,143 @@ func TestUnknownFlagShouldReturnSameErrorRegardlessOfArgPosition(t *testing.T) { }) } } + +func TestNFlagForFlags(t *testing.T) { + var rootNFlag, childNFlag int + rootCmd := &Command{ + Use: "root", + Run: func(cmd *Command, _ []string) { + rootNFlag = cmd.Flags().NFlag() + }, + } + childCmd := &Command{ + Use: "child", + Run: func(cmd *Command, args []string) { + childNFlag = cmd.Flags().NFlag() + }, + } + rootCmd.AddCommand(childCmd) + + rootCmd.PersistentFlags().Bool("rp", false, "") + rpFlag := rootCmd.PersistentFlags().Lookup("rp") + childCmd.PersistentFlags().Bool("cp", false, "") + childCmd.Flags().Int("int", 0, "") + + output, err := executeCommand(rootCmd, "--rp") + if output != "" { + t.Errorf("Unexpected output: %v", output) + } + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if rootNFlag != 1 { + t.Errorf("Expected NFlag: %v, got %v", 1, rootNFlag) + } + // set Changed false for the next test + rpFlag.Changed = false + + output, err = executeCommand(rootCmd, "child", "--rp", "--cp", "--int", "10") + if output != "" { + t.Errorf("Unexpected output: %v", output) + } + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if childNFlag != 3 { + t.Errorf("Expected NFlag: %v, got %v", 3, childNFlag) + } +} + +func TestNFlagForLocalFlags(t *testing.T) { + var localNFlag int + rootCmd := &Command{ + Use: "root", + Run: emptyRun, + } + childCmd := &Command{ + Use: "child", + Run: func(cmd *Command, args []string) { + localNFlag = cmd.LocalFlags().NFlag() + }, + } + rootCmd.AddCommand(childCmd) + + rootCmd.PersistentFlags().Bool("rp", false, "") + childCmd.PersistentFlags().Bool("cp", false, "") + childCmd.Flags().Int("int", 0, "") + + output, err := executeCommand(rootCmd, "child", "--rp", "--cp", "--int", "10") + if output != "" { + t.Errorf("Unexpected output: %v", output) + } + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if localNFlag != 2 { // LocalFlags().NFlag() ignores '--rp' + t.Errorf("Expected NFlag: %v, got %v", 2, localNFlag) + } +} + +func TestNFlagForLocalNonPersistentFlags(t *testing.T) { + var localNonPNFlag int + rootCmd := &Command{ + Use: "root", + Run: emptyRun, + } + childCmd := &Command{ + Use: "child", + Run: func(cmd *Command, args []string) { + localNonPNFlag = cmd.LocalNonPersistentFlags().NFlag() + }, + } + rootCmd.AddCommand(childCmd) + + rootCmd.PersistentFlags().Bool("rp", false, "") + childCmd.PersistentFlags().Bool("cp", false, "") + childCmd.Flags().Int("int", 0, "") + + output, err := executeCommand(rootCmd, "child", "--rp", "--cp", "--int", "10") + if output != "" { + t.Errorf("Unexpected output: %v", output) + } + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if localNonPNFlag != 1 { // LocalNonPersistentFlags().NFlag() ignores '--rp' and '--cp' + t.Errorf("Expected NFlag: %v, got %v", 1, localNonPNFlag) + } +} + +func TestRemoveParentPersistentArgs(t *testing.T) { + rootCmd := &Command{Use: "root", Run: emptyRun} + childCmd := &Command{Use: "child", Run: emptyRun} + rootCmd.AddCommand(childCmd) + + rootCmd.PersistentFlags().BoolP("rp", "r", false, "") + rootCmd.PersistentFlags().Int("ri", 0, "") + childCmd.PersistentFlags().Bool("cp", false, "") + childCmd.Flags().Int("int", 0, "") + + output, err := executeCommand(rootCmd, "child", "--rp", "--ri", "10", "--cp", "--int", "10") + if output != "" { + t.Errorf("Unexpected output: %v", output) + } + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + args := rootCmd.args + _, args, _ = rootCmd.Find(args) + + gotLocalArgs := childCmd.removeParentPersistentArgs(args, childCmd.lflags) + expectedLocalArgs := []string{"--cp", "--int", "10"} + if !reflect.DeepEqual(gotLocalArgs, expectedLocalArgs) { + t.Errorf("Expected localArgs: %v, got %v", expectedLocalArgs, gotLocalArgs) + } + + gotLocalNonPersistentArgs := childCmd.removeParentPersistentArgs(args, childCmd.lnpflags) + expectedLocalNonPersistentArgs := []string{"--int", "10"} + if !reflect.DeepEqual(gotLocalNonPersistentArgs, expectedLocalNonPersistentArgs) { + t.Errorf("Expected localArgs: %v, got %v", expectedLocalNonPersistentArgs, gotLocalNonPersistentArgs) + } +} From 9a4aaf6d9c3e8a6028c8643ad5c8602b219e5439 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 23 Jul 2023 15:38:41 +0900 Subject: [PATCH 10/10] tiny fix for TestRemoveParentPersistentArgs --- command_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_test.go b/command_test.go index 9a25ba9c..3b6d59d4 100644 --- a/command_test.go +++ b/command_test.go @@ -2852,7 +2852,7 @@ func TestRemoveParentPersistentArgs(t *testing.T) { childCmd.PersistentFlags().Bool("cp", false, "") childCmd.Flags().Int("int", 0, "") - output, err := executeCommand(rootCmd, "child", "--rp", "--ri", "10", "--cp", "--int", "10") + output, err := executeCommand(rootCmd, "child", "-r", "--ri", "10", "--cp", "--int", "10") if output != "" { t.Errorf("Unexpected output: %v", output) }