akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
611 stars 62 forks source link

support "h" custom argument #73

Open jossef opened 4 years ago

jossef commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 1 year ago

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"})