Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Flags #25

Closed
SJD opened this issue Jul 24, 2013 · 3 comments · Fixed by #26
Closed

Help Flags #25

SJD opened this issue Jul 24, 2013 · 3 comments · Fixed by #26

Comments

@SJD
Copy link

SJD commented Jul 24, 2013

Hi, is it a conscious design decision not to have help flags? I just wonder because this seems nasty but I don't know how else to do it.

rnd.Action = func(context *cli.Context) {

    // halp hax
    for _, comm := range rnd.Commands {
        if comm.HasName("help") {
            comm.Action(context)
            os.Exit(0)
        }
    }

    // do some stuff in the default (empty) context
    fmt.Printf("Debug: %v\n", context.Bool("debug"))
    fmt.Printf("Port: %d\n", context.Int("port"))
}

Or maybe I'm just missing something fundamental =]

@codegangsta
Copy link
Contributor

There is a help command that is build into the library, although it would be nice to have help flags handled automagically as well. I'm going to keep this issue around and work on it soon.

Thanks for submitting the issue :)

@SJD
Copy link
Author

SJD commented Jul 24, 2013

Yeah, I started out by defining the help flag in help.go (next to the automagic version), and then special casing it by calling showAppHelp, or some such, after a check for the GlobalBool just before the version processing, but it was messy, and I don't really want to be customising cli if I can help it. I understand you have the help command, which I guess is aimed at providing help for other sub commands. In my case, I have no subcommands (although I may add some in this or other apps), and so the default behaviour is just for the process to start.

All I was after was the auto-generated help and exit when people do the ubiquitous -h/ --help. Having to do " help" is surprising for most users - especially as -h/ --help do nothing (if you override the default top level action) so you don't get to see that there even /is/ a help command. Perhaps you could even expose something like that showAppHelp in the public cli API with an optional message which gives people the ability to invoke it at will with contextual information for the user.

Just some thoughts. Anywho, thanks for the package =]

@codegangsta
Copy link
Contributor

Handling -h / --help should be pretty easy. Right now I think the flags package hijacks it but it shouldn't be too hard to trigger trigger the help action when those flags are present.

I will start working on this sometime tomorrow.

Thanks

Sent from my iPhone

On Jul 23, 2013, at 9:10 PM, Sam Duncan notifications@github.com wrote:

Yeah, I started out by defining the help flag in help.go (next to the automagic version), and then special casing it by calling showAppHelp, or some such, after a check for the GlobalBool just before the version processing, but it was messy, and I don't really want to be customising cli if I can help it. I understand you have the help command, which I guess is aimed at providing help for other sub commands. In my case, I have no subcommands (although I may add some in this or other apps), and so the default behaviour is just for the process to start.

All I was after was the auto-generated help and exit when people do the ubiquitous -h/ --help. Having to do " help" is surprising for most users - especially as -h/ --help do nothing (if you override the default top level action) so you don't get to see that there even /is/ a help command. Perhaps you could even expose something like that showAppHelp in the public cli API with an optional message which gives people the ability to invoke it at will with contextual information for the user.

Just some thoughts. Anywho, thanks for the package =]


Reply to this email directly or view it on GitHub.

codegangsta added a commit that referenced this issue Jul 25, 2013
JMS #25: Added support for help flags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants