Repository navigation
--help #2515
|
I'm using v3. Is there a canonically accepted urfave/cli-way to distinguish among the following cases:
In cases 1 and 2, I would like to display a man page for |
Replies: 2 comments
|
Hey! I had a look through the v3 source, and cases 1, 2 and 3 all end up in
Something like this: cli.ShowRootCommandHelp = func(cmd *cli.Command) error {
return showManPage() // your man page
}
app := &cli.Command{
Name: "myapp",
Commands: []*cli.Command{
{
Name: "help",
Aliases: []string{"h"},
ArgsUsage: "[command]",
Action: func(ctx context.Context, cmd *cli.Command) error {
if name := cmd.Args().First(); name != "" {
return cli.ShowCommandHelp(ctx, cmd.Root(), name)
}
return cli.DefaultShowRootCommandHelp(cmd.Root()) // list of commands
},
},
// ... your other commands
},
}Fair warning: I only read through the code and have not run this, so give it a quick try on your side. Hope it helps! |
|
Thanks! This wasn't exactly what I wanted but it was close enough so that I could tweak it myself. I'm rewriting an app I wrote in Ruby many years ago in Go...mostly as a learning experience. The Ruby app was written using a gem called Since I know how the end product is supposed to work, I'm not having to try to figure that out while I'm coding...just re-implementing existing functionality. It makes the development process a lot easier. |
Hey! I had a look through the v3 source, and cases 1, 2 and 3 all end up in
helpCommandAction, which callsShowRootCommandHelpfor each of them. That is whyHelpPrinterturns everything into the same thing. The good news is there are a couple of hooks that let you split them up:cli.ShowRootCommandHelpis a package-level var, so you can replace it. That covers cases 1 and 2 (no args /--help).help, the built-in one is not added, so you can handle case 3 on its own.myapp mycommand --help) never goes throughShowRootCommandHelp, so it keeps working as before.Something like this: