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

Option to disable replacement of "_" with "-" in named cli arguments #220

Open
pppmlt opened this issue Jan 24, 2024 · 3 comments
Open

Option to disable replacement of "_" with "-" in named cli arguments #220

pppmlt opened this issue Jan 24, 2024 · 3 comments

Comments

@pppmlt
Copy link

pppmlt commented Jan 24, 2024

When dispatching a function like the following

def example(*args, this_is_a_long_name): [..]
the cli argument will have the "_" replaced with "-".

I would like to have the CLI arguments names (--this_is_a_long_name) to be identical to my function argument names (this_is_a_long_name). Is there any way to achieve this?

@neithere
Copy link
Owner

Hi @pppmlt, thank you for your interest in Argh!

I'm afraid underscores are not supported in long option names at the moment.

While it's of course possible to implement, I'm not sure if it should be done. The GNU Program Argument Syntax Conventions explicitly recommends the --foo-bar style:

POSIX recommends [...]
GNU adds long options to these conventions. Long options consist of -- followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique.

The purpose of Argh is to map function signatures to CLI patterns. This means translation between two different worlds and conventions that exist there. That's why we introduce the leading hyphens where you don't have them in Python function arguments, for example. So I think it's reasonable to stick to the GNU convention for argument syntax.

I would close the issue but please feel free to reopen it if you have a valid use case.

@pppmlt
Copy link
Author

pppmlt commented Jan 29, 2024

Thank you for explaining the reasoning behind this. The use-case I had in mind is related to Azure ML and their CLI syntax.
To specify inputs/outputs and commands to be run in ML pipelines one can use yaml files. Since the ML use-cases typically run python, the inputs/outputs are passed via CLI arguments. You can find an example here here.

Having to write argparse code for these files is painful and verbose. This is why argh would be useful here. However, if one has to use different names "inside" and "outside" of python seems like its bound to cause mistakes.

I do understand that this might be to much of a niche use-case to be implemented here.

@neithere
Copy link
Owner

@pppmlt thank you for explanation and example! That's indeed a valid use case, even if a niche one.

I'll take another look at it and see how to make it configurable. It should be probably on app level, not per command, because inconsistency is worse as a source of errors than the need to convert between dashes and underscores.

(Can't promise a quick fix.)

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

2 participants