JMS #39: App.Run returns an error
This commit is contained in:
parent
0d3c3f4497
commit
e6e641143c
7
app.go
7
app.go
@ -34,7 +34,7 @@ func NewApp() *App {
|
||||
}
|
||||
|
||||
// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
|
||||
func (a *App) Run(arguments []string) {
|
||||
func (a *App) Run(arguments []string) error {
|
||||
// append help to commands
|
||||
if a.Command(helpCommand.Name) == nil {
|
||||
a.Commands = append(a.Commands, helpCommand)
|
||||
@ -54,7 +54,7 @@ func (a *App) Run(arguments []string) {
|
||||
fmt.Println("Incorrect Usage.\n")
|
||||
ShowAppHelp(context)
|
||||
fmt.Println("")
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
checkHelp(context)
|
||||
@ -66,12 +66,13 @@ func (a *App) Run(arguments []string) {
|
||||
c := a.Command(name)
|
||||
if c != nil {
|
||||
c.Run(context)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Run default Action
|
||||
a.Action(context)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns the named command on App. Returns nil if the command does not exist
|
||||
|
@ -32,8 +32,10 @@ func TestApp_Run(t *testing.T) {
|
||||
s = s + c.Args()[0]
|
||||
}
|
||||
|
||||
app.Run([]string{"command", "foo"})
|
||||
app.Run([]string{"command", "bar"})
|
||||
err := app.Run([]string{"command", "foo"})
|
||||
expect(t, err, nil)
|
||||
err = app.Run([]string{"command", "bar"})
|
||||
expect(t, err, nil)
|
||||
expect(t, s, "foobar")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user