我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用argparse._HelpAction()。
def __init__(self): super(DagdaCLIParser, self).__init__() self.parser = DagdaGlobalParser(prog='dagda.py', usage=dagda_global_parser_text, add_help=False) self.parser.add_argument('command', choices=['vuln', 'check', 'history', 'start', 'monitor', 'docker', 'agent']) self.parser.add_argument('-h', '--help', action=_HelpAction) self.parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.7.0') self.args, self.unknown = self.parser.parse_known_args() if self.get_command() == 'vuln': self.extra_args = VulnCLIParser() elif self.get_command() == 'check': self.extra_args = CheckCLIParser() elif self.get_command() == 'history': self.extra_args = HistoryCLIParser() elif self.get_command() == 'start': self.extra_args = StartCLIParser() elif self.get_command() == 'monitor': self.extra_args = MonitorCLIParser() elif self.get_command() == 'docker': self.extra_args = DockerCLIParser() elif self.get_command() == 'agent': self.extra_args = AgentCLIParser() # -- Getters # Gets command
def print_help(parser, color=None): """??????""" help_text = [] for action in parser._actions: if isinstance(action, argparse._HelpAction): continue option_strings = ",".join(action.option_strings) help_text.append(u"{} {}".format(option_strings, action.help)) print "\n", colored("\n".join(help_text), color)
def filter_input_object(self, action): if isinstance(action, argparse._VersionAction): return True if isinstance(action, argparse._HelpAction): return True return False # TODO: maybe this function should move to be near the opposite in webuipage.POST
def add_namespace(self, namespace, parent): desc = '%s sub-command group' % namespace.capitalize() temp = parent.add_parser(namespace, help=desc, description=desc, formatter_class=CustomDescriptionFormatter, add_help=False) temp.add_argument('-h', '--help', dest='_help', action=argparse._HelpAction) sub = temp.add_subparsers(help='Available sub-commands', parser_class=BaseParser) self.sub_map[namespace] = sub return sub
def finish_parser(parser, module_name): logging.debug('Build actual parser for module %s', module_name) module = importlib.import_module(module_name) if hasattr(module, 'configure'): module.configure(parser) parser.set_defaults(_func=module.main) parser.add_argument('-h', '--help', dest='_help', action=argparse._HelpAction) return module.main
def parse_arguments(): parser = argparse.ArgumentParser(description= 'cli tool for creating debians', add_help=False) # parser.add_argument('--generate-only', metavar='', # help='Only generate debian files,\n' # 'Without building the package', # dest='generate_only') parser.add_argument('-v', '--version', help='show version', action='version', version=__version__) parser.add_argument('-h', '--help', action=_HelpAction, help='show help') subparsers = parser.add_subparsers(dest='cmd') build = subparsers.add_parser('build') subparsers.required = True build.set_defaults(action='build') build.add_argument('--install-dependencies', dest='install_dependencies', action='store_true', help='install deb dependencies before build\n' '(used for python virtualenv creation)', default=False) build.add_argument('--no-clean', dest='clean', action='store_false', help='leave behind everything used to ' 'create the debian package', default=True) build.add_argument('-t', '--type', metavar='', dest='project_type', action='store', help='set project type, default: auto detect') build.add_argument('-p', '--path', metavar='', dest='project_path', action='store', default=os.getcwd(), help='set path to project, ' 'default: current location') build.add_argument('-v', '--version', metavar='', dest='custom_version', help='set version manually', action='store') generate = subparsers.add_parser('generate') generate.add_argument('-p', '--path', metavar='', dest='project_path', action='store', default=os.getcwd(), help='set path to project, ' 'default: current location') generate.add_argument('-v', '--version', metavar='', dest='custom_version', help='set version manually', action='store') return parser.parse_args()