Create a parser given the command-line arguments, creates a parser
        Return True if the programme must exit.
513916
def manage_options(self):
        
        self.parser = self.create_parser()
        self.options, self.args = self.parser.parse_args(self.argv)

        self.do_imports()

        if self.options.callback and not callable(self.options.callback):
            self.parser.error('The callback is not callable')

        self.logger_level = None
        if self.options.logger_level:
            if self.options.logger_level.isdigit():
                self.options.logger_level = int(self.options.logger_level)
            else:
                try:
                    self.options.logger_level = getattr(logging, self.options.logger_level.upper())
                except:
                    self.parser.error('Invalid logger-level %s' % self.options.logger_level)

        if self.options.max_loops is not None and self.options.max_loops < 0:
            self.parser.error('The max-loops argument (%s) must be a <positive></positive> integer' % self.options.max_loops)

        if self.options.max_duration is not None and self.options.max_duration < 0:
            self.parser.error('The max-duration argument (%s) must be a positive integer' % self.options.max_duration)

        if self.options.timeout is not None and self.options.timeout < 0:
            self.parser.error('The timeout argument (%s) must be a positive integer (including 0)' % self.options.timeout)

        if self.options.fetch_priorities_delay is not None and self.options.fetch_priorities_delay <= 0:
            self.parser.error('The fetch-priorities-delay argument (%s) must be a positive integer' % self.options.fetch_priorities_delay)

        if self.options.fetch_delayed_delay is not None and self.options.fetch_delayed_delay <= 0:
            self.parser.error('The fetch-delayed-delay argument (%s) must be a positive integer' % self.options.fetch_delayed_delay)

        if self.options.requeue_times is not None and self.options.requeue_times < 0:
            self.parser.error('The requeue-times argument (%s) must be a positive integer (including 0)' % self.options.requeue_times)

        if self.options.requeue_delay_delta is not None and self.options.requeue_delay_delta < 0:
            self.parser.error('The rrequeue-delay-delta argument (%s) must be a positive integer (including 0)' % self.options.requeue_delay_delta)

        self.database_config = None
        if self.options.database:
            host, port, db = self.options.database.split(':')
            self.database_config = dict(host=host, port=int(port), db=int(db))

        self.update_title = self.options.update_title
102029
def run_from_argv(self, prog, subcommand, global_options, argv):
        
        self.prog_name = prog
        parser = self.create_parser(prog, subcommand)
        options, args = parser.parse_args(argv)
        self.global_options = global_options
        self.options = options
        self.args = args
        self.execute(args, options, global_options)
571309
def main():
	
	parser = cli.Cli()
	parser.parse(sys.argv[1:])
	return parser.run()
646310
def main(args=None):
    
    # Base command line parser. Help is not allowed because command
    # line is parsed in two stages - in the first stage is found setting
    # module of the application, in the second stage are found management
    # command's arguments.
    parser = ArgumentParser(add_help=False)
    parser.add_argument(
        '-s', '--settings',
        dest='settings', action='store', type=str, default=None,
        help=_('application settings module')
    )

    # Get settings module
    try:
        settings = get_app_settings(parser, args)
    except ImportError as exc:
        parser.error(_("Invalid application settings module: {}").format(exc))

    # Get management commands and add their arguments into command
    # line parser
    commands = get_management_commands(settings)
    subparsers = parser.add_subparsers(
        dest='action', help=_('specify action')
    )
    for command_cls in six.itervalues(commands):
        subparser = subparsers.add_parser(
            command_cls.name, help=command_cls.help)
        for command_args, kwargs in command_cls.arguments:
            subparser.add_argument(*command_args, **kwargs)

    # Get config class and add its arguments into command line parser
    if settings:
        config_cls = get_config_class(settings)
        if not issubclass(config_cls, Config):
            raise TypeError(
                "Config class must be subclass of the "
                "shelter.core.config.Config")
        for config_args, kwargs in config_cls.arguments:
            parser.add_argument(*config_args, **kwargs)
    else:
        config_cls = Config

    # Add help argument and parse command line
    parser.add_argument(
        '-h', '--help', action='help',
        help=_('show this help message and exit')
    )
    cmdline_args = parser.parse_args(args)
    if not cmdline_args.action:
        parser.error(_('No action'))

    # Run management command
    command_cls = commands[cmdline_args.action]
    if command_cls.settings_required and not settings:
        parser.error(_(
            "Settings module is not defined. You must either set "
            "'SHELTER_SETTINGS_MODULE' environment variable or "
            "'-s/--settings' command line argument."
        ))
    try:
        config = config_cls(settings, cmdline_args)
    except ImproperlyConfiguredError as exc:
        parser.error(str(exc))
    command = command_cls(config)
    try:
        command()
    except Exception:
        traceback.print_exc(file=sys.stderr)
        sys.stderr.flush()
        if multiprocessing.active_children():
            # If main process has children processes, exit immediately without
            # cleaning. It is a workaround, because parent process waits for
            # non-daemon children.
            os._exit(1)
        sys.exit(1)
    sys.exit(0)
821719
def create_parser(self, prog_name, subcommand):
        
        parser = argparse.ArgumentParser(prog='%s %s' % (prog_name, subcommand), description=self.help)

        parser.add_argument('-v', '--verbosity', action='store', default=1, type=int, choices=range(4),
            help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output'),
        parser.add_argument('--settings',
            help='The Python path to a settings module, e.g. "myproject.settings.main". '
            'If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.'),
        parser.add_argument('--pythonpath',
            help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".'),
        parser.add_argument('--traceback', action='store_true', help='Print traceback on exception'),

        subparsers = parser.add_subparsers(description='JavaScript command to execute')

        for subparser in self.subparsers:
            subparser(self, subparsers)

        return parser
555147
def create_parser(self):
        
        return OptionParser(prog=self.prog_name,
                            usage=self.usage(),
                            version='%%prog %s' % self.get_version(),
                            option_list=self.option_list)
85302
def make_parser():
    

    parser = argparse.ArgumentParser(description='BERNARD CLI utility')
    sp = parser.add_subparsers(help='Sub-command')

    parser_run = sp.add_parser('run', help='Run the BERNARD server')
    parser_run.set_defaults(action='run')

    parser_sheet = sp.add_parser('sheet', help='Import files from Google '
                                               'Sheets')
    parser_sheet.set_defaults(action='sheet')
    parser_sheet.add_argument(
        '--auth_host_name',
        default='localhost',
        help='Hostname when running a local web server.'
    )
    parser_sheet.add_argument(
        '--noauth_local_webserver',
        action='store_true',
        default=False,
        help='Do not run a local web server.'
    )
    parser_sheet.add_argument(
        '--auth_host_port',
        default=[8080, 8090],
        type=int,
        nargs='*',
        help='Port web server should listen on.'
    )
    parser_sheet.add_argument(
        '--logging_level',
        default='ERROR',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
        help='Set the logging level of detail.'
    )

    parser_sp = sp.add_parser('start_project', help='Starts a project')
    parser_sp.set_defaults(action='start_project')
    parser_sp.add_argument(
        'project_name',
        help='A snake-case name for your project'
    )
    parser_sp.add_argument(
        'dir',
        help='Directory to store the project'
    )

    return parser
320258
def create_parser():
    """"""
    parser = argparse.ArgumentParser(description=docstring_summary(__doc__),
                                     prog='autopep8')
    parser.add_argument('--version', action='version',
                        version='%(prog)s {} ({})'.format(
                            __version__, _get_package_version()))
    parser.add_argument('-v', '--verbose', action='count',
                        default=0,
                        help='print verbose messages; '
                             'multiple -v result in more verbose messages')
    parser.add_argument('-d', '--diff', action='store_true',
                        help='print the diff for the fixed source')
    parser.add_argument('-i', '--in-place', action='store_true',
                        help='make changes to files in place')
    parser.add_argument('--global-config', metavar='filename',
                        default=DEFAULT_CONFIG,
                        help='path to a global pep8 config file; if this file '
                             'does not exist then this is ignored '
                             '(default: {})'.format(DEFAULT_CONFIG))
    parser.add_argument('--ignore-local-config', action='store_true',
                        help="don't look for and apply local config files; "
                             'if not passed, defaults are updated with any '
                             "config files in the project's root directory")
    parser.add_argument('-r', '--recursive', action='store_true',
                        help='run recursively over directories; '
                             'must be used with --in-place or --diff')
    parser.add_argument('-j', '--jobs', type=int, metavar='n', default=1,
                        help='number of parallel jobs; '
                             'match CPU count if value is less than 1')
    parser.add_argument('-p', '--pep8-passes', metavar='n',
                        default=-1, type=int,
                        help='maximum number of additional pep8 passes '
                             '(default: infinite)')
    parser.add_argument('-a', '--aggressive', action='count', default=0,
                        help='enable non-whitespace changes; '
                             'multiple -a result in more aggressive changes')
    parser.add_argument('--experimental', action='store_true',
                        help='enable experimental fixes')
    parser.add_argument('--exclude', metavar='globs',
                        help='exclude file/directory names that match these '
                             'comma-separated globs')
    parser.add_argument('--list-fixes', action='store_true',
                        help='list codes for fixes; '
                        'used by --ignore and --select')
    parser.add_argument('--ignore', metavar='errors', default='',
                        help='do not fix these errors/warnings '
                             '(default: {})'.format(DEFAULT_IGNORE))
    parser.add_argument('--select', metavar='errors', default='',
                        help='fix only these errors/warnings (e.g. E4,W)')
    parser.add_argument('--max-line-length', metavar='n', default=79, type=int,
                        help='set maximum allowed line length '
                             '(default: %(default)s)')
    parser.add_argument('--line-range', '--range', metavar='line',
                        default=None, type=int, nargs=2,
                        help='only fix errors found within this inclusive '
                             'range of line numbers (e.g. 1 99); '
                             'line numbers are indexed at 1')
    parser.add_argument('--indent-size', default=DEFAULT_INDENT_SIZE,
                        type=int, help=argparse.SUPPRESS)
    parser.add_argument('--hang-closing', action='store_true',
                        help='hang-closing option passed to pycodestyle')
    parser.add_argument('--exit-code', action='store_true',
                        help='change to behavior of exit code.'
                             ' default behavior of return value, 0 is no '
                             'differences, 1 is error exit. return 2 when'
                             ' add this option. 2 is exists differences.')
    parser.add_argument('files', nargs='*',
                        help="files to format or '-' for standard in")

    return parser
366631
def make(parser):
    """"""
    s = parser.add_subparsers(
        title='commands',
        metavar='COMMAND',
        help='description',
        )

    def install_f(args):
        install(args)
    install_parser = install_subparser(s)
    install_parser.set_defaults(func=install_f)
14749
def run_with_standalone_parser(self):
        
        parser = argparse.ArgumentParser(description=self.description())
        self.configure_parser(parser)
        self.run(parser.parse_args())
1312986
def parse_args(self):
        
        # compile the parser
        self._compile()
        # clear the args
        self.args = None
        self._self_event('before_parse', 'parse', *sys.argv[1:], **{})
        # list commands/subcommands in argv
        cmds = [cmd for cmd in sys.argv[1:] if not cmd.startswith("-")]
        if (len(cmds) > 0 and not utils.check_help() and self.default_cmd
                and cmds[0] not in self.commands):
            # if we have at least one command which is not an help command
            # and we have a default command and the first command in arguments
            # is not in commands we insert the default command as second
            # argument (actually the first command)
            sys.argv.insert(1, self.default_cmd)
        # let's parse the arguments
        self.args = self.parser.parse_args()
        # set up the output.
        if self.args:
            # if we have some arguments
            if self.add_output and self.args.output is not None:
                # If add_output is True and we have an output file
                # setup the encoding
                self.encoding = self.args.encoding
                if self.args.encoding.lower() == 'raw':
                    # if we have passed a raw encoding we will write directly
                    # to the output file.
                    self._output = open(self.args.output, self.args.write_mode)
                else:
                    # else we will use the codecs module to write to the
                    # output file.
                    import codecs
                    self._output = codecs.open(
                        self.args.output, self.args.write_mode,
                        encoding=self.args.encoding)
            if self._cfg_factory:
                # if we have a config factory setup the config file with the
                # right param
                self.cfg_file = self.args.config
            # now is parsed.
            self._is_parsed = True
        return self
722707
def create_parser(self):
        """"""
        parser = argparse.ArgumentParser(
            description=PROGRAM_DESCRIPTION,
            formatter_class=argparse.RawDescriptionHelpFormatter,
            epilog=textwrap.dedent(PROGRAM_EPILOG))

        parser.add_argument(
            'filename',
            metavar='FILE_NAME',
            nargs='*',
            help='the I/O file name')

        subparsers = parser.add_subparsers(
            dest='parser', title='markdown parser')
        subparsers.required = True

        # github + cmark + gitlab + commonmarker.
        github = subparsers.add_parser(
            'github',
            aliases=['cmark', 'gitlab', 'commonmarker'],
            description='Use Commonmark rules to generate an output. If no \
                         option is selected, the default output will be an \
                         unordered list with the respective default values \
                         as listed below')
        megroup = github.add_mutually_exclusive_group()
        megroup.add_argument(
            '-u',
            '--unordered-list-marker',
            choices=md_parser['github']['list']['unordered']['bullet_markers'],
            nargs='?',
            const=md_parser['github']['list']['unordered']['default_marker'],
            help='set the marker and enables unordered list. Defaults to ' +
            md_parser['github']['list']['unordered']['default_marker'])
        megroup.add_argument(
            '-o',
            '--ordered-list-marker',
            choices=md_parser['github']['list']['ordered']['closing_markers'],
            nargs='?',
            const=md_parser['github']['list']['ordered']
            ['default_closing_marker'],
            help='set the marker and enables ordered lists. Defaults to ' +
            md_parser['github']['list']['ordered']['default_closing_marker'])
        github.add_argument(
            '-l',
            '--header-levels',
            choices=[
                str(i)
                for i in range(1, md_parser['github']['header']['max_levels'] +
                               1)
            ],
            nargs='?',
            const=str(md_parser['github']['header']['default_keep_levels']),
            help='set the maximum level of headers to be considered as part \
                  of the TOC. Defaults to ' + str(
                md_parser['github']['header']['default_keep_levels']))
        github.set_defaults(
            header_levels=md_parser['github']['header']['default_keep_levels'])

        # Redcarpet.
        redcarpet = subparsers.add_parser(
            'redcarpet',
            description='Use Redcarpet rules to generate an output. If no \
                         option is selected, the default output will be an \
                         unordered list with the respective default values \
                         as listed below. Gitlab rules are the same as \
                         Redcarpet except that conflicts are avoided with \
                         duplicate headers.')

        megroup = redcarpet.add_mutually_exclusive_group()
        megroup.add_argument(
            '-u',
            '--unordered-list-marker',
            choices=md_parser['redcarpet']['list']['unordered']
            ['bullet_markers'],
            nargs='?',
            const=md_parser['redcarpet']['list']['unordered']
            ['default_marker'],
            help='set the marker and enables unordered list. Defaults to ' +
            md_parser['redcarpet']['list']['unordered']['default_marker'])
        megroup.add_argument(
            '-o',
            '--ordered-list-marker',
            choices=md_parser['redcarpet']['list']['ordered']
            ['closing_markers'],
            nargs='?',
            const=md_parser['redcarpet']['list']['ordered']
            ['default_closing_marker'],
            help='set the marker and enables ordered lists. Defaults to ' +
            md_parser['redcarpet']['list']['ordered']['default_closing_marker']
        )
        redcarpet.add_argument(
            '-l',
            '--header-levels',
            choices=[
                str(i) for i in range(
                    1, md_parser['redcarpet']['header']['max_levels'] + 1)
            ],
            nargs='?',
            const=str(md_parser['redcarpet']['header']['default_keep_levels']),
            help='set the maximum level of headers to be considered as part \
                  of the TOC. Defaults to ' + str(
                md_parser['redcarpet']['header']['default_keep_levels']))
        redcarpet.set_defaults(header_levels=md_parser['redcarpet']['header']
                               ['default_keep_levels'])

        c_or_i = parser.add_mutually_exclusive_group()
        c_or_i.add_argument(
            '-c',
            '--no-list-coherence',
            action='store_true',
            help='avoids checking for TOC list coherence')
        c_or_i.add_argument(
            '-i',
            '--no-indentation',
            action='store_true',
            help='avoids adding indentations to the TOC')

        parser.add_argument(
            '-l',
            '--no-links',
            action='store_true',
            help='avoids adding links to the TOC')
        parser.add_argument(
            '-m',
            '--toc-marker',
            metavar='TOC_MARKER',
            help='set the string to be used as the marker for positioning the \
                  table of contents. Defaults to ' +
            common_defaults['toc_marker'])
        parser.add_argument(
            '-p',
            '--in-place',
            action='store_true',
            help='overwrite the input file')
        parser.add_argument(
            '-v',
            '--version',
            action='version',
            version=VERSION_NAME + ' ' + VERSION_NUMBER)

        parser.set_defaults(toc_marker=common_defaults['toc_marker'])
        parser.set_defaults(func=CliToApi().write_toc)

        return parser
234670
def create_parser(self, prog_name, subcommand):
        
        parser = OptionParser(prog=prog_name,
                              usage=self.usage(subcommand),
                              option_list=self.option_list)
        return parser
31181
def _create_parser(self):
        
        parser = CommandParser(get_internal_version_str())
        parser.register_list_command(self._setup_run_command(ListCommand))
        parser.register_upload_command(self._setup_run_command(UploadCommand))
        parser.register_add_user_command(self._setup_run_command(AddUserCommand))
        parser.register_remove_user_command(self._setup_run_command(RemoveUserCommand))
        parser.register_download_command(self._setup_run_command(DownloadCommand))
        parser.register_share_command(self._setup_run_command(ShareCommand))
        parser.register_deliver_command(self._setup_run_command(DeliverCommand))
        parser.register_delete_command(self._setup_run_command(DeleteCommand))
        parser.register_list_auth_roles_command(self._setup_run_command(ListAuthRolesCommand))
        return parser
72643
def _make_argparser(self):
        """"""
        self.argparser = ShellArgumentParser(prog='')
        subparsers = self.argparser.add_subparsers()

        for name in self.get_names():
            if name.startswith('parser_'):
                parser = subparsers.add_parser(name[7:])
                parser.set_defaults(func=getattr(self, 'arg_' + name[7:]))
                getattr(self, name)(parser)

        self.argparser_completer = None

        try:
            import argcomplete
        except ImportError:
            pass
        else:
            os.environ.setdefault("_ARGCOMPLETE_COMP_WORDBREAKS", " \t\"'")
            self.argparser_completer = argcomplete.CompletionFinder(self.argparser)
737346
def cmd_terminate(self, argv, help):
        """"""
        from ploy.common import yesno
        parser = argparse.ArgumentParser(
            prog="%s terminate" % self.progname,
            description=help,
        )
        instances = self.get_instances(command='terminate')
        parser.add_argument("instance", nargs=1,
                            metavar="instance",
                            help="Name of the instance from the config.",
                            choices=sorted(instances))
        args = parser.parse_args(argv)
        instance = instances[args.instance[0]]
        if not yesno("Are you sure you want to terminate '%s'?" % instance.config_id):
            return
        instance.hooks.before_terminate(instance)
        instance.terminate()
        instance.hooks.after_terminate(instance)
523118
def parser(self):
        
        parser = argparse.ArgumentParser(description=self.description,
                                         epilog=self.epilog)
        parser.add_argument('--version',
                            action='version',
                            version=self.version)
        return self.add_to_parser(parser)