Use Argparse to parse command-line arguments.

    :param argv: list of arguments to parse (``sys.argv[1:]``)
    :type argv: ``list``
    :return: parsed arguments
    :rtype: :py:class:`argparse.Namespace`
186769
def parse_args(argv):
    
    p = argparse.ArgumentParser(
        description='pypi-download-stats - Calculate detailed download stats '
                    'and generate HTML and badges for PyPI packages - '
                    '<%s>' % PROJECT_URL,
        prog='pypi-download-stats'
    )
    p.add_argument('-V', '--version', action='version',
                   version='%(prog)s ' + VERSION)
    p.add_argument('-v', '--verbose', dest='verbose', action='count',
                   default=0,
                   help='verbose output. specify twice for debug-level output.')
    m = p.add_mutually_exclusive_group()
    m.add_argument('-Q', '--no-query', dest='query', action='store_false',
                   default=True, help='do not query; just generate output '
                                      'from cached data')
    m.add_argument('-G', '--no-generate', dest='generate', action='store_false',
                   default=True, help='do not generate output; just query '
                                      'data and cache results')
    p.add_argument('-o', '--out-dir', dest='out_dir', action='store', type=str,
                   default='./pypi-stats', help='output directory (default: '
                                                './pypi-stats')
    p.add_argument('-p', '--project-id', dest='project_id', action='store',
                   type=str, default=None,
                   help='ProjectID for your Google Cloud user, if not using '
                        'service account credentials JSON file')
    # @TODO this is tied to the DiskDataCache class
    p.add_argument('-c', '--cache-dir', dest='cache_dir', action='store',
                   type=str, default='./pypi-stats-cache',
                   help='stats cache directory (default: ./pypi-stats-cache)')
    p.add_argument('-B', '--backfill-num-days', dest='backfill_days', type=int,
                   action='store', default=7,
                   help='number of days of historical data to backfill, if '
                        'missing (defaut: 7). Note this may incur BigQuery '
                        'charges. Set to -1 to backfill all available history.')
    g = p.add_mutually_exclusive_group()
    g.add_argument('-P', '--project', dest='PROJECT', action='append', type=str,
                   help='project name to query/generate stats for (can be '
                        'specified more than once; '
                        'this will reduce query cost for multiple projects)')
    g.add_argument('-U', '--user', dest='user', action='store', type=str,
                   help='Run for all PyPI projects owned by the specified'
                        'user.')
    args = p.parse_args(argv)
    return args
980664
def _get_command_and_argv(argv):
    # type: (typing.List[str]) -> typing.Tuple[str, typing.List[str]]
    
    command_name = argv[0]
    if not command_name:
        argv = argv[1:]
    elif command_name == settings.command:
        argv.remove(command_name)
    return command_name, argv
110662
def main(args):
    
    try:
        import __main__
        parser = argparse.ArgumentParser(
            usage='%(prog)s [options] command\n\nVersion\n  %(prog)s version '
            + str(__version__),
            formatter_class=argparse.RawTextHelpFormatter)
        parser.add_argument('--version', action='version',
                            version='%(prog)s ' + str(__version__))
        build_subcommands_parser(parser, __main__)

        if len(args) <= 1:
            parser.print_help()
            return 1

        options = parser.parse_args(args[1:])
        # Filter out options with are not part of the function prototype.
        func_args = filter_subcommand_args(options.func, options)
        options.func(**func_args)

    except RuntimeError as err:
        LOGGER.error(err)
        return err.code
412334
def callfunc(self, argv=None):
        
        if not self.checked:
            self.check_arguments()
            self.checked = True
        namespace = self.parentparser.parse_args(argv or sys.argv[1:])
        return self.func(**vars(namespace))
302205
def run_from_argv(self, argv):
        
        try:
            return self.main(args=argv[2:], standalone_mode=False)
        except click.ClickException as e:
            if getattr(e.ctx, 'traceback', False):
                raise
            e.show()
            sys.exit(e.exit_code)
626361
def parse_command_line(self, argv=None):
        
        if self.config:
            parser = argparse.ArgumentParser(add_help=False)
            self.settings['config'].add_argument(parser)
            opts, _ = parser.parse_known_args(argv)
            if opts.config is not None:
                self.set('config', opts.config)

            self.params.update(self.import_from_module())

        parser = self.parser()
        opts = parser.parse_args(argv)
        for k, v in opts.__dict__.items():
            if v is None:
                continue
            self.set(k.lower(), v)
352270
def parse_arguments():
    
    parser = argparse.ArgumentParser()

    parser.add_argument('file', metavar="FILE", nargs='+',
                        help='file to be made executable')
    parser.add_argument("-p", "--python", metavar="VERSION",
                        help="python version (2 or 3)")
    parser.add_argument('-v', '--version', action='version',
                        version='%(prog)s ' + __version__, help='show version')
    parser.add_argument('-r', '--recursive', action='store_true',
                        help='recursively iterate the directories')

    args = parser.parse_args()
    return args
334984
def args_parser(self, parser_func: CommandHandler_T) -> CommandHandler_T:
        
        self.cmd.args_parser_func = parser_func
        return parser_func
167782
def parse_arguments():
    
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-c", dest="count", default=0, type=int,
        help="Number of pings to send"
    )
    parser.add_argument(
        "-i", dest="interval", default=1, type=float, help="Ping interval"
    )
    parser.add_argument(
        "-d", dest="timings", default=False, action="store_true",
        help="Show timings for the entire connection"
    )
    parser.add_argument(
        'destination', nargs='+', help='Destination host or URL'
    )
    args = parser.parse_args()
    return args, args.destination
980393
def parse_command_line(self, argv=None):
        
        argv = sys.argv[1:] if argv is None else argv
        self.argv = [py3compat.cast_unicode(arg) for arg in argv]

        # Append Provider Class to the list of configurable items.
        ProviderClass = getattr(providers, self.provider_type)
        self.classes.append(ProviderClass)

        if any(x in self.argv for x in ('-h', '--help-all', '--help')):
            self.print_help('--help-all' in self.argv)
            self.exit(0)

        if '--version' in self.argv or '-V' in self.argv:
            self.print_version()
            self.exit(0)

        # Generate a configuration file if flag is given.
        if '--generate-config' in self.argv:
            conf = self.generate_config_file()
            with open(self.config_file, 'w') as f:
                f.write(conf)
            self.exit(0)

        # If not config, parse commands.
        ## Run sanity checks.
        # Check that the minimum number of arguments have been called.
        if len(self.argv) < 2:
            raise JhubctlError(
                "Not enough arguments. \n\n"
                "Expected: jhubctl <action> <resource> <name>")

        # Check action
        self.resource_action = self.argv[0]
        if self.resource_action not in self.subcommands:
            raise JhubctlError(
                f"Subcommand is not recognized; must be one of these: {self.subcommands}")

        # Check resource
        self.resource_type = self.argv[1]
        if self.resource_type not in self.resources:
            raise JhubctlError(
                f"First argument after a subcommand must one of these"
                f"resources: {self.resources}"
            )

        # Get name of resource.
        try:
            self.resource_name = self.argv[2]
        except IndexError:
            if self.resource_action != "get":
                raise JhubctlError(
                    "Not enough arguments. \n\n"
                    "Expected: jhubctl <action> <resource> <name>")
            else:
                self.resource_name = None

        # flatten flags&aliases, so cl-args get appropriate priority:
        flags, aliases = self.flatten_flags()
        loader = KVArgParseConfigLoader(argv=argv, aliases=aliases,
                                        flags=flags, log=self.log)
        config = loader.load_config()
        self.update_config(config)
        # store unparsed args in extra_args
        self.extra_args = loader.extra_args
1212514
def get_arg_parser (self, **kwargs):
        
        import argparse
        ap = argparse.ArgumentParser (
            prog = kwargs['argv0'],
            description = self.summary,
        )
        return ap
1201837
def parse_args(argv):
    
    p = argparse.ArgumentParser(
        description='webhook2lambda2sqs - Generate code and manage '
                    'infrastructure for receiving webhooks with AWS API '
                    'Gateway and pushing to SQS via Lambda - <%s>' % PROJECT_URL
    )
    p.add_argument('-c', '--config', dest='config', type=str,
                   action='store', default='config.json',
                   help='path to config.json (default: ./config.json)')
    p.add_argument('-v', '--verbose', dest='verbose', action='count',
                   default=0,
                   help='verbose output. specify twice for debug-level output.')
    p.add_argument('-V', '--version', action='version',
                   version='webhook2lambda2sqs v%s <%s>' % (
                       VERSION, PROJECT_URL
                   ))
    p.add_argument('-T', '--tf-version', dest='tf_ver', action='store',
                   type=str, default='0.9.0',
                   help='terraform version to generate configurations for')
    subparsers = p.add_subparsers(title='Action (Subcommand)', dest='action',
                                  metavar='ACTION', description='Action to '
                                  'perform; each action may take further '
                                  'parameters. Use ACTION -h for subcommand-'
                                  'specific options and arguments.')
    subparsers.add_parser(
        'generate', help='generate lambda function and terraform configs in ./'
    )
    tf_parsers = [
        ('genapply', 'generate function and terraform configs in ./, then run '
                     'terraform apply'),
        ('plan', 'run terraform plan to show changes which will be made'),
        ('apply', 'run terraform apply to apply changes/create infrastructure'),
        ('destroy',
         'run terraform destroy to completely destroy infrastructure')
    ]
    tf_p_objs = {}
    for cname, chelp in tf_parsers:
        tf_p_objs[cname] = subparsers.add_parser(cname, help=chelp)
        tf_p_objs[cname].add_argument('-t', '--terraform-path', dest='tf_path',
                                      action='store', default='terraform',
                                      type=str, help='path to terraform '
                                                     'binary, if not in PATH')
        tf_p_objs[cname].add_argument('-S', '--no-stream-tf', dest='stream_tf',
                                      action='store_false', default=True,
                                      help='DO NOT stream Terraform output to '
                                           'STDOUT (combined) in realtime')
    apilogparser = subparsers.add_parser('apilogs', help='show last 10 '
                                         'CloudWatch Logs entries for the '
                                         'API Gateway')
    apilogparser.add_argument('-c', '--count', dest='log_count', type=int,
                              default=10, help='number of log entries to show '
                              '(default 10')
    logparser = subparsers.add_parser('logs', help='show last 10 CloudWatch '
                                      'Logs entries for the function')
    logparser.add_argument('-c', '--count', dest='log_count', type=int,
                           default=10, help='number of log entries to show '
                                            '(default 10')
    queueparser = subparsers.add_parser('queuepeek', help='show messages from '
                                        'one or all of the SQS queues')
    queueparser.add_argument('-n', '--name', type=str, dest='queue_name',
                             default=None, help='queue name to read (defaults '
                                                'to None to read all)')
    queueparser.add_argument('-d', '--delete', action='store_true',
                             dest='queue_delete', default=False,
                             help='delete messages after reading')
    queueparser.add_argument('-c', '--count', dest='msg_count', type=int,
                             default=10, help='number of messages to read from '
                                              'each queue (default 10)')
    testparser = subparsers.add_parser('test', help='send test message to '
                                                    'one or more endpoints')
    testparser.add_argument('-t', '--terraform-path', dest='tf_path',
                            action='store', default='terraform',
                            type=str, help='path to terraform '
                            'binary, if not in PATH')
    testparser.add_argument('-n', '--endpoint-name', dest='endpoint_name',
                            type=str, default=None,
                            help='endpoint name (default: None, to send to '
                                 'all endpoints)')
    subparsers.add_parser(
        'example-config', help='write example config to STDOUT and description '
                               'of it to STDERR, then exit'
    )
    args = p.parse_args(argv)
    if args.action is None:
        # for py3, which doesn't raise on this
        sys.stderr.write("ERROR: too few arguments\n")
        raise SystemExit(2)
    return args
730126
def parse_arg_list(param_start):
    
    values = [arg[len(param_start):]
              for arg in sys.argv
              if arg.startswith(param_start)]

    # remove recognized arguments from the sys.argv
    otherArgs = [arg
                 for arg in sys.argv
                 if not arg.startswith(param_start)]
    sys.argv = otherArgs

    return values
692076
def parse_args(args=None):
    """"""
    parser = argparse.ArgumentParser()

    parser.add_argument(
        '-w', '--window',
        default="pyqt5",
        choices=find_window_classes(),
        help='Name for the window type to use',
    )
    parser.add_argument(
        '-fs', '--fullscreen',
        action="store_true",
        help='Open the window in fullscreen mode',
    )
    parser.add_argument(
        '-vs', '--vsync',
        type=str2bool,
        default="1",
        help="Enable or disable vsync",
    )
    parser.add_argument(
        '-s', '--samples',
        type=int,
        default=4,
        help="Specify the desired number of samples to use for multisampling",
    )
    parser.add_argument(
        '-c', '--cursor',
        type=str2bool,
        default="true",
        help="Enable or disable displaying the mouse cursor",
    )

    return parser.parse_args(args or sys.argv[1:])
1203471
def parse_arguments(argv):
    
    parser = argparse.ArgumentParser(description='seqmagick - Manipulate ' + \
       ' sequence files.', prog='seqmagick')

    parser.add_argument('-V', '--version', action='version',
            version='seqmagick v' + version,
            help="Print the version number and exit")
    parser.add_argument('-v', '--verbose', dest='verbosity',
            action='count', default=1,
            help="Be more verbose. Specify -vv or -vvv for even more")
    parser.add_argument('-q', '--quiet', action='store_const', const=0,
            dest='verbosity', help="Suppress output")

    # Subparsers
    subparsers = parser.add_subparsers(dest='subparser_name')

    parser_help = subparsers.add_parser('help',
            help='Detailed help for actions using help <action>')

    parser_help.add_argument('action')

    # Add actions
    actions = {}
    for name, mod in subcommands.itermodules():
        subparser = subparsers.add_parser(name, help=mod.__doc__,
                description=mod.__doc__)
        mod.build_parser(subparser)
        actions[name] = mod.action

    arguments = parser.parse_args(argv)
    arguments.argv = argv
    action = arguments.subparser_name

    if action == 'help':
        return parse_arguments([str(arguments.action), '-h'])

    return actions[action], arguments
830393
def parse_command_line_arguments(argparse_parser, init_indent=5, subs_indent=5,
                                 line_width=76):
    """"""
    # Redirect stdout and stderr to prettify help or usage output from argparse.
    old_stdout = sys.stdout # save stdout
    old_stderr = sys.stderr # save stderr
    sys.stdout = RedirectHelp(sys.stdout, help_string_replacement_pairs,
            init_indent, subs_indent, line_width) # redirect stdout to add postprocessor
    sys.stderr = RedirectHelp(sys.stderr, help_string_replacement_pairs,
            init_indent, subs_indent, line_width) # redirect stderr to add postprocessor

    # Run the actual argument-parsing operation via argparse.
    args = argparse_parser.parse_args()

    # The argparse class has finished its argument-processing, so now no more
    # usage or help messages will be printed.  So restore stdout and stderr
    # to their usual settings, except with self-flushing added.
    sys.stdout = SelfFlushingOutstream(old_stdout)
    sys.stderr = SelfFlushingOutstream(old_stderr)

    return args
943896
def argparser_factory(self):
        

        return ArgumentParser(
            prog=self.prog, description=self.__doc__, add_help=False,
        )