I created the next "parent" parser:
parent_parser = argparse.ArgumentParser(add_help=False)
base_group = parser.add_argument_group(title = "global arguments")
base_group.add_argument("-l", "--log-file", metavar="FILE", help="set log file (default no log)")
base_group.add_argument("-c", "--clear-log", action="store_true", default=False, help="clear log file before logging")
mutex_group = base_group.add_mutually_exclusive_group()
mutex_group.add_argument("-v", "--verbose", action="store_true", default=False, help="print logs verbosity")
mutex_group.add_argument("-q", "--quiet", action="store_true", default=False, help="suppress every normal output")
If I use this parser as parent in an other one, then I would like to see in the help the next:
usage: my_program.py [-h] [-l FILE] [-c] [-v | -q ] [<the parent arguments ...>] Desc... optional arguments: <the my_program.py arguments> global arguments: -l FILE, --log-file FILE set log file (default no log) -c, --clear-log clear log file before logging -v, --verbose print logs verbosity -q, --quiet suppress every normal output
But unfortunately the arguments from mutex group (-v and -q) are shown in "optional arguments" part. Why? Is it a bug? Or do I make something wrongly?
UPDATE:
I created a bug for this problem: http://bugs.python.org/issue25882. See this bug for my simple code and its output for this situation.