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

How to override HelpFlags? #119

Closed
aviddiviner opened this issue Apr 8, 2016 · 4 comments
Closed

How to override HelpFlags? #119

aviddiviner opened this issue Apr 8, 2016 · 4 comments

Comments

@aviddiviner
Copy link

First up, thanks for the amazing package. Very cool, I plan to make use of it in my app. I really like the ability to handle sub-commands as well as flags.

I'm struggling to see how to override the default HelpFlag and message. I have the following app, based on one of your examples:

package main

import (
    "gopkg.in/alecthomas/kingpin.v2"
    "os"
)

var (
    app          = kingpin.New(os.Args[0], "A command-line chat application.")
    debug        = app.Flag("debug", "Enable debug mode.").Bool()
    register     = app.Command("register", "Register a new user.")
    registerNick = register.Arg("nick", "Nickname for user.").Required().String()
)

func init() {
    app.HelpFlag = app.Flag("help", "Show help.")
    app.HelpFlag.Bool()
    // This gives me an error:
    // error: duplicate long flag --help, try --help

    app.HelpFlag = app.Flag("foo", "Show help.")
    app.HelpFlag.Bool()
    // This shows both help flags:
    //
    //   Flags:
    //     --help   Show context-sensitive help (also try --help-long and --help-man).
    //     --debug  Enable debug mode.
    //     --foo    Show help.
}

func main() {
    switch kingpin.MustParse(app.Parse(os.Args[1:])) {
    // Register user
    case register.FullCommand():
        println(*registerNick)
    }
}

Can you point me in the right direction?

@aviddiviner
Copy link
Author

I've tried this, and it also doesn't work:

var (
    app = func() *kingpin.Application {
        a := kingpin.New(os.Args[0], "A command-line chat application.")
        a.HelpFlag = a.Flag("foo", "Show help.")
        a.HelpFlag.Bool()
        return a
    }()

    // This also shows both help flags:
    //
    //   Flags:
    //     --help   Show context-sensitive help (also try --help-long and --help-man).
    //     --foo    Show help.
)

@alecthomas
Copy link
Owner

What do you mean exactly by "override"?

HelpFlag is designed to be mutated in place and not overridden. To replace the entire help you need to specify an alternative usage template via app.UsageTemplate(). There are several alternatives included that may be used as starting points.

@aviddiviner
Copy link
Author

Sure. I'm probably missing something.

Tell me then, how would I go about replacing this message:

--help   Show context-sensitive help (also try --help-long and --help-man).

With this:

--help   Show help.

@alecthomas alecthomas mentioned this issue Apr 9, 2016
28 tasks
@alecthomas
Copy link
Owner

You can not alter the help string for an existing flag. I've added this to the feature list for v3.

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

2 participants