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

Add an argument group for required parsed args #299

Merged
merged 2 commits into from
Jan 8, 2020

Conversation

gerritdm
Copy link
Contributor

@gerritdm gerritdm commented Jan 6, 2020

This way the --help message will be more clear and won't list the required arguments (e.g. --scenario) under optional arguments, which is the default for flags (--foo or -f), whether they are required or not.

Related to #111.

More background: https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments.

This way the --help message will be more clear and won't list the
required arguments under optional arguments, which is the default
for argument flags (--arg or -a), whether they are required or not.
@gerritdm gerritdm added the type: refactor code clean-up label Jan 6, 2020
@anamileva
Copy link
Member

Is there any way to show the required arguments before the optional arguments?

@gerritdm
Copy link
Contributor Author

gerritdm commented Jan 8, 2020

Yes, here are some options: https://stackoverflow.com/questions/39047075/reorder-python-argparse-argument-groups.

I'll get this implemented shortly.

Edit: the preferred answer doesn't work unfortunately because of the way how parsers are combined when you use the parent = [] function. Even if you explicitly create an optional group in the parents, and do that after creating the required group in another parent, for some reason the optional group will still be first (even if I set add_help of the child to false, and manually add it later to an explicitly defined optional group).

There is an easy hacky way but that accesses a private list and has internal dependencies that might not last (see last commit).

@anamileva
Copy link
Member

There is an easy hacky way but that accesses a private list and has internal dependencies that might not last (see last commit).

Good enough for now given we document it.

@gerritdm gerritdm merged commit 4762058 into master Jan 8, 2020
@gerritdm gerritdm deleted the required_arg_parser_fix branch January 8, 2020 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor code clean-up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants