File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments