Python argparse._HelpAction() Examples

The following are code examples for showing how to use argparse._HelpAction(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: dagda   Author: eliasgranderubio   File: dagda_cli_parser.py    (license) View Source Project 6 votes vote down vote up
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 
Example 2
Project: girlfriend   Author: chihongze   File: cmdargs.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 3
Project: argparseweb   Author: nirizr   File: page.py    (license) View Source Project 5 votes vote down vote up
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 
Example 4
Project: cligraphy   Author: Netflix-Skunkworks   File: parsers.py    (license) View Source Project 5 votes vote down vote up
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 
Example 5
Project: cligraphy   Author: Netflix-Skunkworks   File: parsers.py    (license) View Source Project 5 votes vote down vote up
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 
Example 6
Project: debpackager   Author: urban48   File: main.py    (license) View Source Project 4 votes vote down vote up
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()