Skip to content
Myr

Provide the length of Args when a -- is found in commandline

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

This allows a program to know what args came before the -- and what args came after.

authored by Eric Paris · committed by Eric Paris · parent 4b76e97 · Browse files · 2 files+12 added−2 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−2 removed

  • other:+12 added−2 removed

2 files+12 added−2 removed

modified:cobra_test.go+8 added-2 removed
414 unmodified lines
415 }416}417418func TestFlagLong(t *testing.T) {419 noRRSetupTest("echo --intone=13 something here")419 noRRSetupTest("echo --intone=13 something -- here")420421 if cmdEcho.ArgsLenAtDash() != 1 {422 t.Errorf("expected argsLenAtDash: %d but got %d", 1, cmdRootNoRun.ArgsLenAtDash())423 }424 if strings.Join(te, " ") != "something here" {425 t.Errorf("flags didn't leave proper args remaining..%s given", te)426 }427 if flagi1 != 13 {
4 unmodified lines
432 }433}434435func TestFlagShort(t *testing.T) {433 noRRSetupTest("echo -i13 something here")436 noRRSetupTest("echo -i13 -- something here")437438 if cmdEcho.ArgsLenAtDash() != 0 {439 t.Errorf("expected argsLenAtDash: %d but got %d", 0, cmdRootNoRun.ArgsLenAtDash())440 }441 if strings.Join(te, " ") != "something here" {442 t.Errorf("flags didn't leave proper args remaining..%s given", te)443 }444 if flagi1 != 13 {
602 unmodified lines
modified:command.go+4 added
468 unmodified lines
469470 return findRoot(c)471}472473func (c *Command) ArgsLenAtDash() int {474 return c.Flags().ArgsLenAtDash()475}476477func (c *Command) execute(a []string) (err error) {478 if c == nil {479 return fmt.Errorf("Called Execute() on a nil Command")480 }
666 unmodified lines