本文整理匯總了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
)
示例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)
示例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)
示例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
示例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
示例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
示例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'
示例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
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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}