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

support "h" custom argument #73

Open
jossef opened this issue Oct 15, 2020 · 3 comments
Open

support "h" custom argument #73

jossef opened this issue Oct 15, 2020 · 3 comments
Labels
enhancement help wanted Test case missing Test cases for related issue are not present

Comments

@jossef
Copy link

jossef commented Oct 15, 2020

If I define

host := parser.String("h", "host", &argparse.Options{Required: false, Help: "listening host", Default: "127.0.0.1"})
// ...

I'll get a panic ->

panic: unable to add String: short name h occurs more than once

This is because there's a built-in -h/--help already occupied it.

For now I can workaround it by using a different letter, but It would be a nice to have support for h 😁

@akamensky
Copy link
Owner

That would be great. I realized that this was not a very good design choice. However this was already implemented this way.

I think this can be achieved without breaking compatibility for existing code by adding a method to re-define help argument (or perhaps entirely unset it depending on method arguments). Then this method would need to be called anywhere before setting new -h argument.

PR for this change is welcome.

@akamensky akamensky added Test case missing Test cases for related issue are not present help wanted enhancement labels Oct 15, 2020
@akamensky
Copy link
Owner

@jossef FWIW, there is DisableHelp() method that removes use of -h|--help as automagic help arguments. This was added previously for a similar use, but I have not used it myself, so not sure if that works for your use case.

@sayap
Copy link

sayap commented Dec 14, 2022

With SetHelp from #50, we can remove the short name for help with:

parser.SetHelp("", "help")
host := parser.String("h", "host", &argparse.Options{Required: true, Help: "Host"})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Test case missing Test cases for related issue are not present
Projects
None yet
Development

No branches or pull requests

3 participants