Skip to content

Commit e6e6411

Browse files
committed
JMS #39: App.Run returns an error
1 parent 0d3c3f4 commit e6e6411

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

app.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewApp() *App {
3434
}
3535

3636
// Entry point to the cli app. Parses the arguments slice and routes to the proper flag/args combination
37-
func (a *App) Run(arguments []string) {
37+
func (a *App) Run(arguments []string) error {
3838
// append help to commands
3939
if a.Command(helpCommand.Name) == nil {
4040
a.Commands = append(a.Commands, helpCommand)
@@ -54,7 +54,7 @@ func (a *App) Run(arguments []string) {
5454
fmt.Println("Incorrect Usage.\n")
5555
ShowAppHelp(context)
5656
fmt.Println("")
57-
os.Exit(1)
57+
return err
5858
}
5959

6060
checkHelp(context)
@@ -66,12 +66,13 @@ func (a *App) Run(arguments []string) {
6666
c := a.Command(name)
6767
if c != nil {
6868
c.Run(context)
69-
return
69+
return nil
7070
}
7171
}
7272

7373
// Run default Action
7474
a.Action(context)
75+
return nil
7576
}
7677

7778
// Returns the named command on App. Returns nil if the command does not exist

app_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ func TestApp_Run(t *testing.T) {
3232
s = s + c.Args()[0]
3333
}
3434

35-
app.Run([]string{"command", "foo"})
36-
app.Run([]string{"command", "bar"})
35+
err := app.Run([]string{"command", "foo"})
36+
expect(t, err, nil)
37+
err = app.Run([]string{"command", "bar"})
38+
expect(t, err, nil)
3739
expect(t, s, "foobar")
3840
}
3941

0 commit comments

Comments
 (0)