def get_parser(self, prog_name): """Return an :class:`argparse.ArgumentParser`. """ parser = argparse.ArgumentParser( description=self.get_description(), prog=prog_name, ) return parser
def get_parser(self, prog_name): """Return an :class:`argparse.ArgumentParser`. """ parser = argparse.ArgumentParser( description=self.get_description(), epilog=self.get_epilog(), prog=prog_name, formatter_class=_SmartHelpFormatter, ) return parser
def build_option_parser(self, description, version, argparse_kwargs=None): """Return an argparse option parser for this application. Subclasses may override this method to extend the parser with more global options. :param description: full description of the application :paramtype description: str :param version: version number for the application :paramtype version: str :param argparse_kwargs: extra keyword argument passed to the ArgumentParser constructor :paramtype extra_kwargs: dict """ argparse_kwargs = argparse_kwargs or {} parser = argparse.ArgumentParser(description=description, add_help=False, **argparse_kwargs) parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(version), help='display version information and exit') verbose_group = parser.add_mutually_exclusive_group() verbose_group.add_argument( '-v', '--verbose', action='count', dest='verbose_level', default=self.DEFAULT_VERBOSE_LEVEL, help='provide a detailed output', ) verbose_group.add_argument( '-q', '--quiet', action='store_const', dest='verbose_level', const=0, help='display warnings and errors only', ) parser.add_argument( '--log-file', action='store', default=None, help='record output into a designated file', ) if self.deferred_help: parser.add_argument( '-h', '--help', dest='deferred_help', action='store_true', help="display help message", ) else: parser.add_argument( '-h', '--help', action=HelpAction, nargs=0, default=self, # tricky help="show the help message", ) parser.add_argument( '--debug', default=False, action='store_true', help='enable debugging mode', ) return parser
def build_option_parser(self, description, version, argparse_kwargs=None): """Return an argparse option parser for this application. Subclasses may override this method to extend the parser with more global options. :param description: full description of the application :paramtype description: str :param version: version number for the application :paramtype version: str :param argparse_kwargs: extra keyword argument passed to the ArgumentParser constructor :paramtype extra_kwargs: dict """ argparse_kwargs = argparse_kwargs or {} parser = argparse.ArgumentParser(description=description, add_help=False, **argparse_kwargs) parser.add_argument( '--version', action='version', version='%(prog)s {0}'.format(version), ) verbose_group = parser.add_mutually_exclusive_group() verbose_group.add_argument( '-v', '--verbose', action='count', dest='verbose_level', default=self.DEFAULT_VERBOSE_LEVEL, help='Increase verbosity of output. Can be repeated.', ) verbose_group.add_argument( '-q', '--quiet', action='store_const', dest='verbose_level', const=0, help='Suppress output except warnings and errors.', ) parser.add_argument( '--log-file', action='store', default=None, help='Specify a file to log output. Disabled by default.', ) if self.deferred_help: parser.add_argument( '-h', '--help', dest='deferred_help', action='store_true', help="Show help message and exit.", ) else: parser.add_argument( '-h', '--help', action=HelpAction, nargs=0, default=self, # tricky help="Show this help message and exit.", ) parser.add_argument( '--debug', default=False, action='store_true', help='Show tracebacks on errors.', ) return parser