The situation
One module (let's call it A
) implements a "primary" argparse parser, that parses known arguments common for all children classes (using parser.parse_known_args(argv)
). Then, it passes remaining arguments to another object that it's calling. Let's assume it may be either object of class B
or C
. Both B
and C
have their own argparse parsers which parse remaining arguments (using parser.parse_args(argv)
). They take different arguments, specific to class B
or C
.
Example snippet from class A
:
parser = argparse.ArgumentParser(
description="Parent parser",
formatter_class=argparse.RawTextHelpFormatter,
allow_abbrev=False
)
parser.add_argument('--argument_A', action="append", default=None,
help="Help of first argument of parser A")
known, remaining_args = parser.parse_known_args(argv)
my_obj = self.create_obj(b_or_c, remaining_args)
Example snippet from class B
:
parser = argparse.ArgumentParser(
description="Class B parser",
formatter_class=argparse.RawTextHelpFormatter,
allow_abbrev=False
)
parser.add_argument('--argument_B', action="append", default=None,
help="Help of first argument of parser B")
B_arguments_parsed = parser.parse_args(argv)
Example snippet from class C
:
parser = argparse.ArgumentParser(
description="Class C parser",
formatter_class=argparse.RawTextHelpFormatter,
allow_abbrev=False
)
parser.add_argument('--argument_C', action="append", default=None,
help="Help of first argument of parser C")
C_arguments_parsed = parser.parse_args(argv)
While implementing passing the arguments and parsing them in the right places was easy, I didn't find a simple solution to print proper help.
The question
How do I implement help message so that my parent parser (from class A
) prints it's own help and help from parser B
or C
?
I would like to see help message from parser A
and, depending on which object was selected, parser B
or C
.