当前位置: 首页>>代码示例>>Python>>正文


Python click.argument方法代码示例

本文整理汇总了Python中click.argument方法的典型用法代码示例。如果您正苦于以下问题:Python click.argument方法的具体用法?Python click.argument怎么用?Python click.argument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在click的用法示例。


在下文中一共展示了click.argument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute_from_file

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def execute_from_file(self, pattern, **_):
        if not pattern:
            message = "\\i: missing required argument"
            return [(None, None, None, message, "", False, True)]
        try:
            with open(os.path.expanduser(pattern), encoding="utf-8") as f:
                query = f.read()
        except IOError as e:
            return [(None, None, None, str(e), "", False, True)]

        if self.destructive_warning and confirm_destructive_query(query) is False:
            message = "Wise choice. Command execution stopped."
            return [(None, None, None, message)]

        on_error_resume = self.on_error == "RESUME"
        return self.pgexecute.run(
            query, self.pgspecial, on_error_resume=on_error_resume
        ) 
开发者ID:dbcli,项目名称:pgcli,代码行数:20,代码来源:main.py

示例2: mkdir

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def mkdir(directory, exists_okay):
    """
    Create a directory on the board.

    Mkdir will create the specified directory on the board.  One argument is
    required, the full path of the directory to create.

    Note that you cannot recursively create a hierarchy of directories with one
    mkdir command, instead you must create each parent directory with separate
    mkdir command calls.

    For example to make a directory under the root called 'code':

      ampy --port /board/serial/port mkdir /code
    """
    # Run the mkdir command.
    board_files = files.Files(_board)
    board_files.mkdir(directory, exists_okay=exists_okay) 
开发者ID:scientifichackers,项目名称:ampy,代码行数:20,代码来源:cli.py

示例3: ls

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def ls(directory, long_format, recursive):
    """List contents of a directory on the board.

    Can pass an optional argument which is the path to the directory.  The
    default is to list the contents of the root, /, path.

    For example to list the contents of the root run:

      ampy --port /board/serial/port ls

    Or to list the contents of the /foo/bar directory on the board run:

      ampy --port /board/serial/port ls /foo/bar

    Add the -l or --long_format flag to print the size of files (however note
    MicroPython does not calculate the size of folders and will show 0 bytes):

      ampy --port /board/serial/port ls -l /foo/bar
    """
    # List each file/directory on a separate line.
    board_files = files.Files(_board)
    for f in board_files.ls(directory, long_format=long_format, recursive=recursive):
        print(f) 
开发者ID:scientifichackers,项目名称:ampy,代码行数:25,代码来源:cli.py

示例4: arg_date

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def arg_date(var='date', metavar='<date>', date_frmt_key='date_frmt'):
    def _arg_date(f):
        def callback(ctx, param, value):
            try:
                value = dt.strptime(value, ctx.params[date_frmt_key])
            except KeyError:
                raise click.ClickException(
                    'Need to use `date_format_opt` when using `date_arg`')
            except ValueError:
                raise click.BadParameter(
                    'Cannot parse {v} to date with format {f}'.format(
                        v=value, f=ctx.params['date_frmt']))
            else:
                return value
        return click.argument(var, metavar=metavar, callback=callback)(f)
    return _arg_date 
开发者ID:ceholden,项目名称:yatsm,代码行数:18,代码来源:options.py

示例5: arg_job_number

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def arg_job_number(f):
    def callback(ctx, param, value):
        try:
            value = int(value)
        except:
            raise click.BadParameter('Must specify an integer >= 0')

        if value < 0:
            raise click.BadParameter('Must specify an integer >= 0')
        elif value == 0:
            return value
        else:
            return value - 1

    return click.argument('job_number', nargs=1, callback=callback,
                          metavar='<job_number>')(f)


# CLI OPTIONS 
开发者ID:ceholden,项目名称:yatsm,代码行数:21,代码来源:options.py

示例6: parse_data

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def parse_data(stats_dir):
    def parse_file(file):
        experiment = None
        base_file = path.basename(file)
        m = SUMMARY_REGEX.match(base_file)
        if m:
            experiment = 'all features'
        m = ANSWER_REGEX.match(base_file)
        if m:
            experiment = m.group(1)
        if experiment is None:
            raise ValueError('Incorrect file name argument: {}'.format(base_file))
        with open(file) as f:
            data = json.load(f)
            return seq(data.items()).map(lambda kv: {
                'experiment': experiment,
                'result': kv[0].replace('Answer.', ''),
                'score': kv[1]
            })

    rows = seq(glob(path.join(stats_dir, 'test*.json')))\
        .sorted().flat_map(parse_file).to_pandas()
    return rows 
开发者ID:Pinafore,项目名称:qb,代码行数:25,代码来源:performance.py

示例7: test_default_if_no_args

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def test_default_if_no_args():
    cli = DefaultGroup()

    @cli.command()
    @click.argument('foo', required=False)
    @click.option('--bar')
    def foobar(foo, bar):
        click.echo(foo)
        click.echo(bar)

    cli.set_default_command(foobar)
    assert r.invoke(cli, []).output.startswith('Usage:')
    assert r.invoke(cli, ['foo']).output == 'foo\n\n'
    assert r.invoke(cli, ['foo', '--bar', 'bar']).output == 'foo\nbar\n'
    cli.default_if_no_args = True
    assert r.invoke(cli, []).output == '\n\n' 
开发者ID:click-contrib,项目名称:click-default-group,代码行数:18,代码来源:test.py

示例8: check_subsampling_params

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def check_subsampling_params(ctx: Context, argument: Argument, value) -> Any:
    subsampling = ctx.params.get('subsampling')

    if not subsampling and value is not None:
        tpl = 'This parameter ({}) only applies to subsampling, to enable it add `--subsampling` to your command'
        app_logger.error(tpl.format(argument.name))
        ctx.abort()

    if argument.name == 'subsampling_log' and subsampling and value is None:
        app_logger.error('''In order to perform subsampling you need to specify whether to log1p input counts or not:
            to do this specify in your command as --subsampling-log [true|false]''')
        ctx.abort()

    defaults = {
        'subsampling_num_pc': 100,
        'subsampling_num_cells': None
    }

    if subsampling and value is None:
        return defaults.get(argument.name, None)

    return value 
开发者ID:Teichlab,项目名称:cellphonedb,代码行数:24,代码来源:method_terminal_commands.py

示例9: definition

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def definition(ctx, name, json, definition_type):  #pylint: disable=unused-argument
    """
    Show policy definition information
    """
    policy_definitions = PolicyDefinitions(ctx.auth, ctx.host)
    policy_data = PolicyData(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    if name:
        policy_definition_dict = policy_definitions.get_policy_definition_dict(definition_type)
        if name in policy_definition_dict:
            policy_definition = policy_data.export_policy_definition_list(policy_definition_dict[name]['type'].lower())
            # list_keys(policy_definition['definition'])
            pp.pprint(policy_definition)
    else:
        policy_definition_list = policy_data.export_policy_definition_list(definition_type)
        pp.pprint(policy_definition_list) 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:19,代码来源:policies.py

示例10: central

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def central(ctx, name, json):  #pylint: disable=unused-argument
    """
    Show central policy information
    """
    central_policy = CentralPolicy(ctx.auth, ctx.host)
    policy_data = PolicyData(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    if name:
        central_policy_dict = central_policy.get_central_policy_dict()
        if name in central_policy_dict:
            if json:
                pp.pprint(central_policy_dict[name])
            else:
                preview = central_policy.get_central_policy_preview(central_policy_dict[name]['policyId'])
                pp.pprint(preview)
    else:
        central_policy_list = policy_data.export_central_policy_list()
        pp.pprint(central_policy_list) 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:21,代码来源:policies.py

示例11: security

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def security(ctx, name, json):  #pylint: disable=unused-argument
    """
    Show security policy information
    """
    security_policy = SecurityPolicy(ctx.auth, ctx.host)
    policy_data = PolicyData(ctx.auth, ctx.host)
    pp = pprint.PrettyPrinter(indent=2)

    if name:
        security_policy_dict = security_policy.get_security_policy_dict()
        if name in security_policy_dict:
            if json:
                pp.pprint(security_policy_dict[name])
            else:
                preview = security_policy.get_security_policy_preview(security_policy_dict[name]['policyId'])
                pp.pprint(preview)
    else:
        security_policy_list = policy_data.export_security_policy_list()
        pp.pprint(security_policy_list) 
开发者ID:CiscoDevNet,项目名称:python-viptela,代码行数:21,代码来源:policies.py

示例12: profiler_arguments

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def profiler_arguments(f):
    @click.argument('argv', nargs=-1)
    @click.option('-m', 'module', type=Module(),
                  help='Run library module as a script.')
    @click.option('-c', 'command', type=Command(),
                  help='Program passed in as string.')
    @wraps(f)
    def wrapped(argv, module, command, **kwargs):
        if module is not None and command is not None:
            raise click.UsageError('Option -m and -c are exclusive')
        script = module or command
        if script is None:
            # -m and -c not passed.
            try:
                script_filename, argv = argv[0], argv[1:]
            except IndexError:
                raise click.UsageError('Script not specified')
            script = Script().convert(script_filename, None, None)
        kwargs.update(script=script, argv=argv)
        return f(**kwargs)
    return wrapped 
开发者ID:what-studio,项目名称:profiling,代码行数:23,代码来源:__main__.py

示例13: test_customized_cli

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def test_customized_cli():
    cli = ProfilingCLI(default='bar')
    @cli.command(aliases=['fooo', 'foooo'])
    def foo():
        pass
    @cli.command()
    @click.argument('l', default='answer')
    @click.option('-n', type=int, default=0)
    def bar(l, n=0):
        click.echo('%s: %d' % (l, n))
    assert len(cli.commands) == 2
    ctx = click.Context(cli)
    assert cli.get_command(ctx, 'foo').name == 'foo'
    assert cli.get_command(ctx, 'fooo').name == 'foo'
    assert cli.get_command(ctx, 'foooo').name == 'foo'
    assert cli.get_command(ctx, 'bar').name == 'bar'
    assert cli.get_command(ctx, 'hello.txt').name == 'bar'
    assert 'Usage:' in cli_runner.invoke(cli, []).output
    assert cli_runner.invoke(cli, ['zero']).output == 'zero: 0\n'
    assert cli_runner.invoke(cli, ['one', '-n', '1']).output == 'one: 1\n'
    assert cli_runner.invoke(cli, ['-n', '42']).output == 'answer: 42\n'
    assert 'no such option' in cli_runner.invoke(cli, ['-x']).output 
开发者ID:what-studio,项目名称:profiling,代码行数:24,代码来源:test_cli.py

示例14: edit_inputs

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def edit_inputs(client, workflow):
    """Edit workflow inputs."""
    for input_ in workflow.inputs:
        new_path = click.prompt(
            '{0._id}'.format(input_),
            default=input_.consumes.path,
        )
        input_.consumes.path = str(
            Path(os.path.abspath(new_path)).relative_to(client.path)
        )

    for step in workflow.subprocesses:
        for argument in step.arguments:
            argument.value = click.prompt(
                '{0._id}'.format(argument),
                default=argument.value,
            )

    return workflow 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:21,代码来源:rerun.py

示例15: cli

# 需要导入模块: import click [as 别名]
# 或者: from click import argument [as 别名]
def cli(context, input, ignore_duplicate_keys):
    """Process and manipulate a CityJSON file, and allow
    different outputs. The different operators can be chained
    to perform several processing in one step, the CityJSON model
    goes through the different operators.

    To get help on specific command, eg for 'validate':

    \b
        cjio validate --help

    Usage examples:

    \b
        cjio example.json info validate
        cjio example.json assign_epsg 7145 remove_textures export output.obj
        cjio example.json subset --id house12 save out.json
    """
    context.obj = {"argument": input} 
开发者ID:cityjson,项目名称:cjio,代码行数:21,代码来源:cjio.py


注:本文中的click.argument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。