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

Conversion of underscores to dashes in argument names #79

Open
anntzer opened this issue Nov 13, 2014 · 3 comments
Open

Conversion of underscores to dashes in argument names #79

anntzer opened this issue Nov 13, 2014 · 3 comments

Comments

@anntzer
Copy link

anntzer commented Nov 13, 2014

Define foo.py as

#!/usr/bin/env python
import argh

@argh.dispatch_command
def main(a_b, *c_d):
    pass

Then

$ ./foo.py -h
usage: foo.py [-h] a-b [c_d [c_d ...]]

positional arguments:
  a-b         None
  c_d         None

optional arguments:
  -h, --help  show this help message and exit

While a minor issue, it seems more consistent if the c_d argument was printed as c-d.

@srkunze
Copy link

srkunze commented Oct 8, 2015

I would like this, too.

@anntzer
Copy link
Author

anntzer commented Mar 10, 2016

Similar issue: having an argument whose name starts with an underscore crashes argh (because it tries to pass "--" / "---foo" to argparse). I think this could be instead a mechanism either for specifying arguments not available on the command line, or the underscore could be removed in case the user wants to define an option whose name would collide with a builtin or a keyword.

@neithere
Copy link
Owner

neithere commented Aug 1, 2016

Hi @anntzer,

First of all, thank you for your effort.

So, given this example:

@argh.dispatch_command
def main(a_b, _c_d, *e_f):
    return a_b, _c_d, *e_f

...in its current state, argh handles it this way:

$ python issue79.py -h
usage: issue79.py [-h] a_b _c_d [e_f [e_f ...]]

positional arguments:
  a_b         -
  _c_d        -
  e_f         -

optional arguments:
  -h, --help  show this help message and exit
$ python issue79.py hello world extra plus
hello
world
('extra', 'plus')

That is, argh doesn't crash and displays all positional argument names with underscore (which could be replaced with a hyphen, but at least it's consistent).

However, this small example does crash argh the way you described

@argh.dispatch_command
def main(_foo=5):
    return _foo

Traceback:

Traceback (most recent call last):
  File "[...]argh/argh/assembling.py", line 307, in set_default_command
    action = parser.add_argument(*dest_or_opt_strings, **draft)
  File "/usr/lib/python3.5/argparse.py", line 1316, in add_argument
    kwargs = self._get_optional_kwargs(*args, **kwargs)
  File "/usr/lib/python3.5/argparse.py", line 1466, in _get_optional_kwargs
    raise ValueError(msg % option_string)
ValueError: dest= is required for options like '---foo'

I suggest that we keep these as separate issues. I'll probably need more time to check this and your patch.

@neithere neithere added this to the 1.0 milestone Feb 7, 2023
@neithere neithere added the needs-design needs design decision label Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants