本文整理匯總了Python中click.Argument方法的典型用法代碼示例。如果您正苦於以下問題:Python click.Argument方法的具體用法?Python click.Argument怎麽用?Python click.Argument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類click
的用法示例。
在下文中一共展示了click.Argument方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: 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
示例2: format_options
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def format_options(self, ctx, formatter):
args = []
opts = []
for param in self.get_params(ctx):
rv = param.get_help_record(ctx)
if rv is not None:
if isinstance(param, click.Argument):
args.append(rv)
else:
opts.append(rv)
if args:
with formatter.section('Arguments'):
formatter.write_dl(args)
if opts:
with formatter.section(self.options_metavar):
formatter.write_dl(opts)
# overridden to set the limit parameter to always be CLI_HELP_STRING_MAX_LEN
示例3: command
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def command(name=None, cls=None, **attrs):
"""
Commands are the basic building block of command line interfaces in
Click. A basic command handles command line parsing and might dispatch
more parsing to commands nested below it.
:param name: the name of the command to use unless a group overrides it.
:param context_settings: an optional dictionary with defaults that are
passed to the context object.
:param params: the parameters to register with this command. This can
be either :class:`Option` or :class:`Argument` objects.
:param help: the help string to use for this command.
:param epilog: like the help string but it's printed at the end of the
help page after everything else.
:param short_help: the short help to use for this command. This is
shown on the command listing of the parent command.
:param add_help_option: by default each command registers a ``--help``
option. This can be disabled by this parameter.
:param options_metavar: The options metavar to display in the usage.
Defaults to ``[OPTIONS]``.
:param args_before_options: Whether or not to display the options
metavar before the arguments.
Defaults to False.
"""
return click.command(name=name, cls=cls or Command, **attrs)
示例4: runs_arg
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def runs_arg(fn):
"""### Specify Runs
You may use one or more `RUN` arguments to indicate which runs
apply to the command. `RUN` may be a run ID, a run ID prefix, or a
one-based index corresponding to a run returned by the list
command.
Indexes may also be specified in ranges in the form `START:END`
where `START` is the start index and `END` is the end
index. Either `START` or `END` may be omitted. If `START` is
omitted, all runs up to `END` are selected. If `END` id omitted,
all runs from `START` on are selected. If both `START` and `END`
are omitted (i.e. the ``:`` char is used by itself) all runs are
selected.
"""
click_util.append_params(
fn, [click.Argument(("runs",), metavar="[RUN...]", nargs=-1)]
)
return fn
示例5: import_params
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def import_params(fn):
click_util.append_params(
fn,
[
runs_support.runs_arg,
click.Argument(("archive",)),
click.Option(
("-m", "--move"),
help="Move imported runs rather than copy.",
is_flag=True,
),
click.Option(
("--copy-resources",),
help="Copy resources for each imported run.",
is_flag=True,
),
runs_support.all_filters,
click.Option(
("-y", "--yes"), help="Do not prompt before importing.", is_flag=True
),
],
)
return fn
示例6: get_params_convertors_ctx_param_name_from_function
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def get_params_convertors_ctx_param_name_from_function(
callback: Optional[Callable[..., Any]]
) -> Tuple[List[Union[click.Argument, click.Option]], Dict[str, Any], Optional[str]]:
params = []
convertors = {}
context_param_name = None
if callback:
parameters = get_params_from_function(callback)
for param_name, param in parameters.items():
if lenient_issubclass(param.annotation, click.Context):
context_param_name = param_name
continue
click_param, convertor = get_click_param(param)
if convertor:
convertors[param_name] = convertor
params.append(click_param)
return params, convertors, context_param_name
示例7: choose_database
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def choose_database(ctx: Context, argument: Argument, value: str) -> Optional[str]:
return DatabaseVersionManager.find_database_for(value)
示例8: get_command
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def get_command(self, ctx, name):
params = [click.Argument(["command"], nargs=-1)]
plugin = pkg_resources.load_entry_point(
"pifpaf", "pifpaf.daemons", name)
params.extend(map(lambda kw: click.Option(**kw), plugin.get_options()))
def _run_cb(*args, **kwargs):
return self._run(name, plugin, ctx, *args, **kwargs)
return click.Command(name=name, callback=_run_cb, params=params)
示例9: argument
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def argument(*param_decls, cls=None, **attrs):
"""
Arguments are positional parameters to a command. They generally
provide fewer features than options but can have infinite ``nargs``
and are required by default.
:param param_decls: the parameter declarations for this option or
argument. This is a list of flags or argument
names.
:param type: the type that should be used. Either a :class:`ParamType`
or a Python type. The later is converted into the former
automatically if supported.
:param required: controls if this is optional or not.
:param default: the default value if omitted. This can also be a callable,
in which case it's invoked when the default is needed
without any arguments.
:param callback: a callback that should be executed after the parameter
was matched. This is called as ``fn(ctx, param,
value)`` and needs to return the value. Before Click
2.0, the signature was ``(ctx, value)``.
:param nargs: the number of arguments to match. If not ``1`` the return
value is a tuple instead of single value. The default for
nargs is ``1`` (except if the type is a tuple, then it's
the arity of the tuple).
:param metavar: how the value is represented in the help page.
:param expose_value: if this is `True` then the value is passed onwards
to the command callback and stored on the context,
otherwise it's skipped.
:param is_eager: eager values are processed before non eager ones. This
should not be set for arguments or it will inverse the
order of processing.
:param envvar: a string or list of strings that are environment variables
that should be checked.
:param help: the help string.
:param hidden: hide this option from help outputs.
Default is True, unless help is given.
"""
return click.argument(*param_decls, cls=cls or Argument, **attrs)
示例10: _format_argument
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def _format_argument(arg):
"""Format the output of a `click.Argument`."""
yield '.. option:: {}'.format(arg.human_readable_name)
yield ''
yield _indent('{} argument{}'.format(
'Required' if arg.required else 'Optional',
'(s)' if arg.nargs != 1 else ''))
示例11: _format_arguments
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def _format_arguments(ctx):
"""Format all `click.Argument` for a `click.Command`."""
params = [x for x in ctx.command.params if isinstance(x, click.Argument)]
for param in params:
for line in _format_argument(param):
yield line
yield ''
示例12: _format_envvar
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def _format_envvar(param):
"""Format the envvars of a `click.Option` or `click.Argument`."""
yield '.. envvar:: {}'.format(param.envvar)
yield ' :noindex:'
yield ''
if isinstance(param, click.Argument):
param_ref = param.human_readable_name
else:
# if a user has defined an opt with multiple "aliases", always use the
# first. For example, if '--foo' or '-f' are possible, use '--foo'.
param_ref = param.opts[0]
yield _indent('Provide a default for :option:`{}`'.format(param_ref))
示例13: _format_argument
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def _format_argument(arg):
"""Format the output of a `click.Argument`."""
yield '.. option:: {}'.format(arg.human_readable_name)
yield ''
yield _indent('{} argument{}'.format(
'Required' if arg.required else 'Optional', '(s)'
if arg.nargs != 1 else ''))
示例14: delete_params
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def delete_params(fn):
click_util.append_params(
fn,
[
click.Argument(
("packages",), metavar="PACKAGE...", nargs=-1, required=True
),
click.Option(
("-y", "--yes",),
help="Do not prompt before uninstalling.",
is_flag=True,
),
],
)
return fn
示例15: remote_arg
# 需要導入模塊: import click [as 別名]
# 或者: from click import Argument [as 別名]
def remote_arg(fn):
"""`REMOTE` is the name of a configured remote. Use ``guild remotes``
to list available remotes.
For information on configuring remotes, see ``guild remotes
--help``.
"""
click_util.append_params(fn, [click.Argument(("remote",))])
return fn