Object for parsing command line strings into Python objects. Keyword Arguments: - prog -- The name of the program (default: ``os.path.basename(sys.argv[0])``) - usage -- A usage message (default: auto-generated from arguments) - description -- A descrip
| 1718 | |
| 1719 | |
| 1720 | class ArgumentParser(_AttributeHolder, _ActionsContainer): |
| 1721 | """Object for parsing command line strings into Python objects. |
| 1722 | |
| 1723 | Keyword Arguments: |
| 1724 | - prog -- The name of the program (default: |
| 1725 | ``os.path.basename(sys.argv[0])``) |
| 1726 | - usage -- A usage message (default: auto-generated from arguments) |
| 1727 | - description -- A description of what the program does |
| 1728 | - epilog -- Text following the argument descriptions |
| 1729 | - parents -- Parsers whose arguments should be copied into this one |
| 1730 | - formatter_class -- HelpFormatter class for printing help messages |
| 1731 | - prefix_chars -- Characters that prefix optional arguments |
| 1732 | - fromfile_prefix_chars -- Characters that prefix files containing |
| 1733 | additional arguments |
| 1734 | - argument_default -- The default value for all arguments |
| 1735 | - conflict_handler -- String indicating how to handle conflicts |
| 1736 | - add_help -- Add a -h/-help option |
| 1737 | - allow_abbrev -- Allow long options to be abbreviated unambiguously |
| 1738 | - exit_on_error -- Determines whether or not ArgumentParser exits with |
| 1739 | error info when an error occurs |
| 1740 | """ |
| 1741 | |
| 1742 | def __init__(self, |
| 1743 | prog=None, |
| 1744 | usage=None, |
| 1745 | description=None, |
| 1746 | epilog=None, |
| 1747 | parents=[], |
| 1748 | formatter_class=HelpFormatter, |
| 1749 | prefix_chars='-', |
| 1750 | fromfile_prefix_chars=None, |
| 1751 | argument_default=None, |
| 1752 | conflict_handler='error', |
| 1753 | add_help=True, |
| 1754 | allow_abbrev=True, |
| 1755 | exit_on_error=True): |
| 1756 | |
| 1757 | superinit = super(ArgumentParser, self).__init__ |
| 1758 | superinit(description=description, |
| 1759 | prefix_chars=prefix_chars, |
| 1760 | argument_default=argument_default, |
| 1761 | conflict_handler=conflict_handler) |
| 1762 | |
| 1763 | # default setting for prog |
| 1764 | if prog is None: |
| 1765 | prog = _os.path.basename(_sys.argv[0]) |
| 1766 | |
| 1767 | self.prog = prog |
| 1768 | self.usage = usage |
| 1769 | self.epilog = epilog |
| 1770 | self.formatter_class = formatter_class |
| 1771 | self.fromfile_prefix_chars = fromfile_prefix_chars |
| 1772 | self.add_help = add_help |
| 1773 | self.allow_abbrev = allow_abbrev |
| 1774 | self.exit_on_error = exit_on_error |
| 1775 | |
| 1776 | add_group = self.add_argument_group |
| 1777 | self._positionals = add_group(_('positional arguments')) |