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

[Q] Exiting on help message. #91

Closed
jmervine opened this issue Jun 4, 2014 · 1 comment
Closed

[Q] Exiting on help message. #91

jmervine opened this issue Jun 4, 2014 · 1 comment

Comments

@jmervine
Copy link
Contributor

jmervine commented Jun 4, 2014

I apologize if this is obvious and I'm just missing it, but I'm trying to figure out how to os.Exit(0) when help is called via help, h, --help and -h. All print the help message, but none exit by default and I can't seem to find a simple way to for the exit. I attempted adding checking to my app.Action declaration, but that seems to be executed only if help isn't specified. This seems like something most applications would want to do by default.

Here's a simplified example -- http://play.golang.org/p/PEdNXSMvJ8.

Cheers and thanks in advance,
J

@jmervine
Copy link
Contributor Author

jmervine commented Jun 5, 2014

I was able to get around this by copying the default HelpPrinter and adding an exit to the end, seems clunky though.

    cli.HelpPrinter = func (templ string, data interface{}) {
        w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
        t := template.Must(template.New("help").Parse(templ))
        err := t.Execute(w, data)
        if err != nil {
            panic(err)
        }
        w.Flush()
        os.Exit(0)
    }

Full example: http://play.golang.org/p/hQLeSGHAEv

@jmervine jmervine closed this as completed Jun 5, 2014
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

No branches or pull requests

1 participant