Show usage and exit with error whenever arguments parsing fails

Signed-off-by: Damien Le Berrigaud <damien@pivotallabs.com>
This commit is contained in:
Casey McTaggart
2013-09-04 13:58:31 -06:00
committed by Damien Le Berrigaud
parent 16d10cc127
commit 3e07cbd8ba
2 changed files with 23 additions and 2 deletions
+15 -1
View File
@@ -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)