Show usage and exit with error whenever arguments parsing fails
Signed-off-by: Damien Le Berrigaud <damien@pivotallabs.com>
This commit is contained in:
committed by
Damien Le Berrigaud
parent
16d10cc127
commit
3e07cbd8ba
+15
-1
@@ -1,5 +1,11 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
Name string
|
||||
ShortName string
|
||||
@@ -17,7 +23,15 @@ func (c Command) Run(ctx *Context) {
|
||||
)
|
||||
|
||||
set := flagSet(c.Name, c.Flags)
|
||||
set.Parse(ctx.Args()[1:])
|
||||
set.SetOutput(ioutil.Discard)
|
||||
err := set.Parse(ctx.Args()[1:])
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Incorrect Usage.\n")
|
||||
ShowCommandHelp(ctx, c.Name)
|
||||
fmt.Println("")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
context := NewContext(ctx.App, set, ctx.globalSet)
|
||||
checkCommandHelp(context, c.Name)
|
||||
|
||||
Reference in New Issue
Block a user