Customizable command not found function

This commit is contained in:
Chris Winslett
2014-03-30 20:40:46 -07:00
parent 3fa24ca4f3
commit 37299d4e5a
3 changed files with 30 additions and 1 deletions

View File

@@ -278,3 +278,26 @@ func TestAppHelpPrinter(t *testing.T) {
t.Errorf("Help printer expected to be called, but was not")
}
}
func TestAppCommandNotFound(t *testing.T) {
beforeRun, subcommandRun := false, false
app := cli.NewApp()
app.CommandNotFound = func(c *cli.Context, command string) {
beforeRun = true
}
app.Commands = []cli.Command{
cli.Command{
Name: "bar",
Action: func(c *cli.Context) {
subcommandRun = true
},
},
}
app.Run([]string{"command", "foo"})
expect(t, beforeRun, true)
expect(t, subcommandRun, false)
}