Skip to content
Myr

Better handling of parsing args to commands, especially the root

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

authored by spf13 · committed by spf13 · parent 2d02c31 · Browse files · 1 file+17 added−1 removed
This commit

State

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

Diff stats

1 file+17 added−1 removed

  • other:+17 added−1 removed

1 file+17 added−1 removed

modified:commander.go+17 added-1 removed
77 unmodified lines
78 // initialize help as the last point possible to allow for user79 // overriding80 c.initHelp()81 if len(c.args) == 0 {82 if len(os.Args) == 1 {83 // If only the executable is called and the root is runnable, run it84 if c.Runnable() {85 argWoFlags := c.Flags().Args()86 c.Run(c.cmd, argWoFlags)87 } else {88 c.Usage()89 }90 } else {82 err = c.execute(os.Args[1:])91 err = c.execute(os.Args[1:])92 }93 } else {94 err = c.execute(c.args)95 }9697 if err != nil {98 c.Println("Error:", err.Error())99 c.Printf("%v: invalid command %#q\n", c.Root().Name(), os.Args[1:])100 c.Printf("Run '%v help' for usage\n", c.Root().Name())101 }102 return103}104105func (c *Commander) out() io.Writer {
63 unmodified lines