imxdparser
Description
The MainParser and ChildParser allows the creation of a fully intermixed argument parser:
Examples
# Start the parser so that the following is valid:
# ./app (...) --cfgfile filename (...)
main_parser = MainParser()
main_parser.add_argument("--version", action="version", version="1.2.3")
main_parser.add_argument("-c", "--cfgfile")
main_parser.attach()
# Add the "one" and "two" options:
subparser = ChildParser(main_parser, "one")
subparser.add_argument("file")
subparser.attach()
subparser = ChildParser(main_parser, "two")
subparser.add_argument("file")
subparser.attach()
# Result (all the following are valid)
# ./app one --cfgfile filename
# ./app --cfgfile filename one
# ./app two --cfgfile filename
# ./app --cfgfile filename two
Classes
- class imxdparser.imxdparser.BaseParser(**kwargs)
- class imxdparser.imxdparser.MainParser(prog: str | None = None, usage: str | None = None, description: str | None = None, epilog: str | None = None, formatter_class=<class 'argparse.RawDescriptionHelpFormatter'>, prefix_chars: str = '-', fromfile_prefix_chars: str | None = None, argument_default=None, conflict_handler: str = 'error', add_help: bool | None = True, allow_abbrev: bool | None = True, exit_on_error: bool | None = True)
Bases:
BaseParser
Root parser which holds as many child parsers as you wish
- __init__(prog: str | None = None, usage: str | None = None, description: str | None = None, epilog: str | None = None, formatter_class=<class 'argparse.RawDescriptionHelpFormatter'>, prefix_chars: str = '-', fromfile_prefix_chars: str | None = None, argument_default=None, conflict_handler: str = 'error', add_help: bool | None = True, allow_abbrev: bool | None = True, exit_on_error: bool | None = True)
Create a base parser that holds an extra internal argument parser.
- Parameters:
prog (dict[str]) – The name of the program (default: sys.argv[0])
usage (str) – A usage message (default: auto-generated from arguments)
description (str) – A description of what the program does
epilog (str) – Text following the argument descriptions
formatter_class – HelpFormatter class for printing help messages. Note: changed from default argparse.HelpFormatter
prefix_chars (str) – Characters that prefix optional arguments
fromfile_prefix_chars – Characters that prefix files containing additional arguments
argument_default – The default value for all arguments
conflict_handler (str) – String indicating how to handle conflicts
add_help (boolean) – Add a -h/-help option
allow_abbrev (bool) – Allow long options to be abbreviated unambiguously
exit_on_error (bool) – Determines whether or not ArgumentParser exits with error info when an error occurs
- class imxdparser.imxdparser.ChildParser(parent=None, prog: str | None = None, usage: str | None = None, description: str | None = None, epilog: str | None = None, formatter_class=<class 'argparse.RawDescriptionHelpFormatter'>, prefix_chars: str = '-', fromfile_prefix_chars: str | None = None, argument_default=None, conflict_handler: str = 'error', add_help: bool | None = True, allow_abbrev: bool | None = True, exit_on_error: bool | None = True)
Bases:
BaseParser
Child parser which holds as many other child parsers as you wish
- __init__(parent=None, prog: str | None = None, usage: str | None = None, description: str | None = None, epilog: str | None = None, formatter_class=<class 'argparse.RawDescriptionHelpFormatter'>, prefix_chars: str = '-', fromfile_prefix_chars: str | None = None, argument_default=None, conflict_handler: str = 'error', add_help: bool | None = True, allow_abbrev: bool | None = True, exit_on_error: bool | None = True)
Create a child parser that holds an extra internal argument parser.
- Parameters:
parent – MainParser or ChildParser this parser depends on.
prog (dict[str]) – The name of the program (default: sys.argv[0])
usage (str) – A usage message (default: auto-generated from arguments)
description (str) – A description of what the program does
epilog (str) – Text following the argument descriptions
formatter_class – HelpFormatter class for printing help messages. Note: changed from default argparse.HelpFormatter
prefix_chars (str) – Characters that prefix optional arguments
fromfile_prefix_chars – Characters that prefix files containing additional arguments
argument_default – The default value for all arguments
conflict_handler (str) – String indicating how to handle conflicts
add_help (boolean) – Add a -h/-help option
allow_abbrev (bool) – Allow long options to be abbreviated unambiguously
exit_on_error (bool) – Determines whether or not ArgumentParser exits with error info when an error occurs