Cli: Default message/action when subcommand is invalid?

Created on 29 Oct 2015  Â·  1Comment  Â·  Source: urfave/cli

I'd like to be able to define a default action/message that would be run when a matching subcommand doesn't exist. Currently, users get a cryptic "No help topic for 'command'":

➜  ~  foo bar
No help topic for 'bar'

Anytime a user uses an invalid subcommand, I'd like to instead print a message and then the usage text. Is this possible today? If not, I'm happy to dive in and make a change if I could get some guidance.

Most helpful comment

Found the super handy CommandNotFound function:

    app.CommandNotFound = func(c *cli.Context, command string) {
        log.Err("No matching command '%s'", command)
        cli.ShowAppHelp(c)
        log.Die("")
    }

(where log is a helper in our app)

>All comments

Found the super handy CommandNotFound function:

    app.CommandNotFound = func(c *cli.Context, command string) {
        log.Err("No matching command '%s'", command)
        cli.ShowAppHelp(c)
        log.Die("")
    }

(where log is a helper in our app)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nokel81 picture Nokel81  Â·  17Comments

lynncyrin picture lynncyrin  Â·  20Comments

odiferousmint picture odiferousmint  Â·  14Comments

johnwyles picture johnwyles  Â·  17Comments

slantview picture slantview  Â·  44Comments