mirror of
https://github.com/spf13/cobra
synced 2024-11-04 21:07:19 +00:00
Merge pull request #160 from eparis/len-at-dash
Provide the length of Args when a -- is found in commandline
This commit is contained in:
commit
53d96508f5
2 changed files with 12 additions and 2 deletions
|
@ -416,8 +416,11 @@ func TestGrandChildSameName(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFlagLong(t *testing.T) {
|
||||
noRRSetupTest("echo --intone=13 something here")
|
||||
noRRSetupTest("echo --intone=13 something -- here")
|
||||
|
||||
if cmdEcho.ArgsLenAtDash() != 1 {
|
||||
t.Errorf("expected argsLenAtDash: %d but got %d", 1, cmdRootNoRun.ArgsLenAtDash())
|
||||
}
|
||||
if strings.Join(te, " ") != "something here" {
|
||||
t.Errorf("flags didn't leave proper args remaining..%s given", te)
|
||||
}
|
||||
|
@ -430,8 +433,11 @@ func TestFlagLong(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFlagShort(t *testing.T) {
|
||||
noRRSetupTest("echo -i13 something here")
|
||||
noRRSetupTest("echo -i13 -- something here")
|
||||
|
||||
if cmdEcho.ArgsLenAtDash() != 0 {
|
||||
t.Errorf("expected argsLenAtDash: %d but got %d", 0, cmdRootNoRun.ArgsLenAtDash())
|
||||
}
|
||||
if strings.Join(te, " ") != "something here" {
|
||||
t.Errorf("flags didn't leave proper args remaining..%s given", te)
|
||||
}
|
||||
|
|
|
@ -470,6 +470,10 @@ func (c *Command) Root() *Command {
|
|||
return findRoot(c)
|
||||
}
|
||||
|
||||
func (c *Command) ArgsLenAtDash() int {
|
||||
return c.Flags().ArgsLenAtDash()
|
||||
}
|
||||
|
||||
func (c *Command) execute(a []string) (err error) {
|
||||
if c == nil {
|
||||
return fmt.Errorf("Called Execute() on a nil Command")
|
||||
|
|
Loading…
Reference in a new issue