本文整理汇总了Python中click.command方法的典型用法代码示例。如果您正苦于以下问题:Python click.command方法的具体用法?Python click.command怎么用?Python click.command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类click
的用法示例。
在下文中一共展示了click.command方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_from_argv
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def run_from_argv(self, argv):
"""
Called when run from the command line.
"""
prog_name = "{} {}".format(os.path.basename(argv[0]), argv[1])
try:
# We won't get an exception here in standalone_mode=False
exit_code = self.main(
args=argv[2:], prog_name=prog_name, standalone_mode=False
)
if exit_code:
sys.exit(exit_code)
except click.ClickException as e:
if getattr(e.ctx, "traceback", False): # NOCOV
raise
e.show()
sys.exit(e.exit_code)
示例2: execute
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def execute(self, *args, **kwargs):
"""
Called when run through `call_command`. `args` are passed through,
while `kwargs` is the __dict__ of the return value of
`self.create_parser('', name)` updated with the kwargs passed to
`call_command`.
"""
# Remove internal Django command handling machinery
kwargs.pop("skip_checks", None)
parent_ctx = click.get_current_context(silent=True)
with self.make_context("", list(args), parent=parent_ctx) as ctx:
# Rename kwargs to to the appropriate destination argument name
opt_mapping = dict(self.map_names())
arg_options = {
opt_mapping.get(key, key): value for key, value in six.iteritems(kwargs)
}
# Update the context with the passed (renamed) kwargs
ctx.params.update(arg_options)
# Invoke the command
self.invoke(ctx)
示例3: __call__
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def __call__(self, func):
module = sys.modules[func.__module__]
# Get the command name as Django expects it
self.name = func.__module__.rsplit(".", 1)[-1]
# Build the click command
decorators = [
click.command(name=self.name, cls=self.cls, **self.kwargs),
] + self.get_params(self.name)
for decorator in reversed(decorators):
func = decorator(func)
# Django expects the command to be callable (it instantiates the class
# pointed at by the `Command` module-level property)...
# ...let's make it happy.
module.Command = lambda: func
return func
示例4: get_command
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def get_command(self, ctx: click.Context, name: str) -> click.Command:
"""Return the relevant command given the context and name.
.. warning::
This differs substantially from Flask in that it allows
for the inbuilt commands to be overridden.
"""
info = ctx.ensure_object(ScriptInfo)
command = None
try:
command = info.load_app().cli.get_command(ctx, name)
except NoAppException:
pass
if command is None:
command = super().get_command(ctx, name)
return command
示例5: cli
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def cli(wio, send):
'''
Sends a UDP command to the wio device.
\b
DOES:
Support "VERSION", "SCAN", "Blank?", "DEBUG", "ENDEBUG: 1", "ENDEBUG: 0"
"APCFG: AP\\tPWDs\\tTOKENs\\tSNs\\tSERVER_Domains\\tXSERVER_Domain\\t\\r\\n",
Note:
1. Ensure your device is Configure Mode.
2. Change your computer network to Wio's AP.
\b
EXAMPLE:
wio udp --send [command], send UPD command
'''
command = send
click.echo("UDP command: {}".format(command))
result = udp.common_send(command)
if result is None:
return debug_error()
else:
click.echo(result)
示例6: _detect_wifi_ssid
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def _detect_wifi_ssid():
system = _system()
if system not in SUPPORTED_SYSTEMS:
return False, 'Unknown operation system {0}'.format(system)
if system == 'Darwin':
command = ['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport', '-I']
pattern = re.compile(r' SSID: (?P<ssid>.+)')
elif system == 'Linux':
command = ['nmcli', '-t', '-f', 'active,ssid', 'dev', 'wifi']
pattern = re.compile(r"yes:'(?P<ssid>.+)'")
else:
command = ['netsh', 'wlan', 'show', 'interfaces']
pattern = re.compile(r' SSID.+: (?P<ssid>.+)\r')
rs = _exec(command)
match = re.search(pattern, rs)
if not match:
return False, rs
return True, match.group('ssid')
示例7: analyze
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def analyze(
context, api_client, api_key, input_file, output_file, output_format, verbose
):
"""Analyze the IP addresses in a log file, stdin, etc."""
if input_file is None:
if sys.stdin.isatty():
output = [
context.command.get_usage(context),
(
"Error: at least one text file must be passed "
"either through the -i/--input_file option or through a shell pipe."
),
]
click.echo("\n\n".join(output))
context.exit(-1)
else:
input_file = click.open_file("-")
if output_file is None:
output_file = click.open_file("-", mode="w")
result = api_client.analyze(input_file)
return result
示例8: list_commands
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def list_commands(self, ctx):
self._load_plugin_commands()
# The commands available is the list of both the application (if
# available) plus the builtin commands.
rv = set(click.Group.list_commands(self, ctx))
info = ctx.ensure_object(ScriptInfo)
try:
rv.update(info.load_app().cli.list_commands(ctx))
except Exception:
# Here we intentionally swallow all exceptions as we don't
# want the help page to break if the app does not exist.
# If someone attempts to use the command we try to create
# the app again and this will give us the error.
# However, we will not do so silently because that would confuse
# users.
traceback.print_exc()
return sorted(rv)
示例9: main
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def main(self, *args, **kwargs):
# Set a global flag that indicates that we were invoked from the
# command line interface. This is detected by Flask.run to make the
# call into a no-op. This is necessary to avoid ugly errors when the
# script that is loaded here also attempts to start a server.
os.environ['FLASK_RUN_FROM_CLI'] = 'true'
if get_load_dotenv(self.load_dotenv):
load_dotenv()
obj = kwargs.get('obj')
if obj is None:
obj = ScriptInfo(create_app=self.create_app)
kwargs['obj'] = obj
kwargs.setdefault('auto_envvar_prefix', 'FLASK')
return super(FlaskGroup, self).main(*args, **kwargs)
示例10: list_commands
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def list_commands(self, ctx):
self._load_plugin_commands()
# The commands available is the list of both the application (if
# available) plus the builtin commands.
rv = set(click.Group.list_commands(self, ctx))
info = ctx.ensure_object(ScriptInfo)
try:
rv.update(info.load_app().cli.list_commands(ctx))
except Exception:
# Here we intentionally swallow all exceptions as we don't
# want the help page to break if the app does not exist.
# If someone attempts to use the command we try to create
# the app again and this will give us the error.
pass
return sorted(rv)
示例11: main
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def main(as_module=False):
this_module = __package__ + '.cli'
args = sys.argv[1:]
if as_module:
if sys.version_info >= (2, 7):
name = 'python -m ' + this_module.rsplit('.', 1)[0]
else:
name = 'python -m ' + this_module
# This module is always executed as "python -m flask.run" and as such
# we need to ensure that we restore the actual command line so that
# the reloader can properly operate.
sys.argv = ['-m', this_module] + sys.argv[1:]
else:
name = None
cli.main(args=args, prog_name=name)
示例12: check_subsampling_params
# 需要导入模块: import click [as 别名]
# 或者: from click import command [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
示例13: dot_plot
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def dot_plot(means_path: str, pvalues_path: str, output_path: str, output_name: str, rows: str,
columns: str, verbose: bool):
try:
r_plotter.dot_plot(means_path=means_path,
pvalues_path=pvalues_path,
output_path=output_path,
output_name=output_name,
rows=rows,
columns=columns)
except MissingR:
print('You cannot perform this plot command unless there is a working R setup according to CellPhoneDB specs')
except RRuntimeException as e:
app_logger.error(str(e))
except:
app_logger.error('Unexpected error')
if verbose:
traceback.print_exc(file=sys.stdout)
else:
app_logger.error('execute with --verbose to see full stack trace')
示例14: heatmap_plot
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def heatmap_plot(meta_path: str, pvalues_path: str, output_path: str, count_name: str, log_name: str,
count_network_name, interaction_count_name, pvalue: float, verbose: bool):
try:
r_plotter.heatmaps_plot(meta_file=meta_path,
pvalues_file=pvalues_path,
output_path=output_path,
count_name=count_name,
log_name=log_name,
count_network_filename=count_network_name,
interaction_count_filename=interaction_count_name,
pvalue=pvalue)
except MissingR:
print('You cannot perform this plot command unless there is a working R setup according to CellPhoneDB specs')
except RRuntimeException as e:
app_logger.error(str(e))
except:
app_logger.error('Unexpected error')
if verbose:
traceback.print_exc(file=sys.stdout)
else:
app_logger.error('execute with --verbose to see full stack trace')
示例15: status
# 需要导入模块: import click [as 别名]
# 或者: from click import command [as 别名]
def status(id):
"""
View status of all jobs in a project.
The command also accepts a specific job name.
"""
if id:
try:
experiment = ExperimentClient().get(normalize_job_name(id))
except FloydException:
experiment = ExperimentClient().get(id)
print_experiments([experiment])
else:
experiments = ExperimentClient().get_all()
print_experiments(experiments)