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
argparse add_mutually_exclusive_group do not print help #68924
Comments
Hi, Here is a sample of what I do: >>> import argparse
>>> main_parser = argparse.ArgumentParser()
>>> group_ex = main_parser.add_mutually_exclusive_group()
>>> group_ex1 = group_ex.add_argument_group()
>>> group_ex1.add_argument('-a', '--atest', help="help about -a") and None
>>> group_ex1.add_argument('-b', '--btest', help="help about -b") and None
>>> group_ex.add_argument('-c', '--ctest', help="help about -c") and None
>>> main_parser.print_help()
usage: [-h] [-a ATEST] [-b BTEST] [-c CTEST] optional arguments: Here is what I would except as help message: >>> main_parser.print_help()
usage: [-h] [[-a ATEST] [-b BTEST]] | [-c CTEST] optional arguments: -a ATEST, --atest ATEST Options '-a' and '-b' are not displayed in the help message due to the "add_mutually_exclusive_group". |
These two types of groups serve different purposes and aren't designed to nest or interact. An argument group groups arguments in the help lines. It does not affect parsing at all. It can't be used to add a 'group' of arguments to another group. A mutually exclusive group produces an error message during parsing, and modifies the usage line. There isn't a way, in the current code, to nest groups of arguments (in some sort of 'any' or 'and' sense) within a mutually exclusive group. It's 'xor' for all arguments. |
@paul: thanks, I'm very surprised because the parsing work well. Moreover it's not said in the documentation that you cannot nest groups. So maybe we should update the documentation and/or improve the module ? |
I'm proposing closing this with reference to http://bugs.python.org/issue22047 That focuses on the issue of adding mutually exclusive group to another exclusive group, but adding Argument Group has the same problems. Solutions, short of the big http://bugs.python.org/issue11588 fix, include code that raises an error the user attempts to nest groups and/or adding a documentation note that nesting does not work. There is one kind of nesting that does work - a mutually exclusive group can be nested inside an Argument Group. The effect is to give the mutually exclusive group a title and help line grouping. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: