本文整理匯總了Python中click.core方法的典型用法代碼示例。如果您正苦於以下問題:Python click.core方法的具體用法?Python click.core怎麽用?Python click.core使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類click
的用法示例。
在下文中一共展示了click.core方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_command
# 需要導入模塊: import click [as 別名]
# 或者: from click import core [as 別名]
def _make_command(self) -> Command:
"""
Make cli.core.Command.
:return: a cli command
"""
return Command(
None, # type: ignore
params=self._make_command_params(),
callback=self._command_callback,
help=self._make_help(),
)
示例2: make_parser
# 需要導入模塊: import click [as 別名]
# 或者: from click import core [as 別名]
def make_parser(self, ctx):
"""Creates the underlying option parser for this command."""
from .parser import Q2Parser
parser = Q2Parser(ctx)
for param in self.get_params(ctx):
param.add_to_parser(parser, ctx)
return parser
# Modified from original:
# < https://github.com/pallets/click/blob/
# c6042bf2607c5be22b1efef2e42a94ffd281434c/click/core.py#L934 >
# Copyright (c) 2014 by the Pallets team.
示例3: format_help_text
# 需要導入模塊: import click [as 別名]
# 或者: from click import core [as 別名]
def format_help_text(self, ctx, formatter):
super().format_help_text(ctx, formatter)
formatter.write_paragraph()
# Modified from original:
# < https://github.com/pallets/click/blob
# /c6042bf2607c5be22b1efef2e42a94ffd281434c/click/core.py#L830 >
# Copyright (c) 2014 by the Pallets team.
示例4: format_usage
# 需要導入模塊: import click [as 別名]
# 或者: from click import core [as 別名]
def format_usage(self, ctx, formatter):
from q2cli.core.config import CONFIG
"""Writes the usage line into the formatter."""
pieces = self.collect_usage_pieces(ctx)
formatter.write_usage(CONFIG.cfg_style('command', ctx.command_path),
' '.join(pieces))
示例5: parse_args
# 需要導入模塊: import click [as 別名]
# 或者: from click import core [as 別名]
def parse_args(self, ctx, args):
from q2cli.core.config import CONFIG
if isinstance(self, click.MultiCommand):
return super().parse_args(ctx, args)
errors = []
parser = self.make_parser(ctx)
skip_rest = False
for _ in range(10): # surely this is enough attempts
try:
opts, args, param_order = parser.parse_args(args=args)
break
except click.ClickException as e:
errors.append(e)
skip_rest = True
if not skip_rest:
for param in click.core.iter_params_for_processing(
param_order, self.get_params(ctx)):
try:
value, args = param.handle_parse_result(ctx, opts, args)
except click.ClickException as e:
errors.append(e)
if args and not ctx.allow_extra_args and not ctx.resilient_parsing:
errors.append(click.UsageError(
'Got unexpected extra argument%s (%s)'
% (len(args) != 1 and 's' or '',
' '.join(map(click.core.make_str, args)))))
if errors:
click.echo(ctx.get_help()+"\n", err=True)
if len(errors) > 1:
problems = 'There were some problems with the command:'
else:
problems = 'There was a problem with the command:'
click.echo(CONFIG.cfg_style('problem',
problems.center(78, ' ')), err=True)
for idx, e in enumerate(errors, 1):
msg = click.formatting.wrap_text(
e.format_message(),
initial_indent=' (%d/%d%s) ' % (idx, len(errors),
'?' if skip_rest else ''),
subsequent_indent=' ')
click.echo(CONFIG.cfg_style('error', msg), err=True)
ctx.exit(1)
ctx.args = args
return args
示例6: format_options
# 需要導入模塊: import click [as 別名]
# 或者: from click import core [as 別名]
def format_options(self, ctx, formatter, COL_MAX=23, COL_MIN=10):
from q2cli.core.config import CONFIG
# write options
opt_groups = {}
records = []
for group, options in self.get_opt_groups(ctx).items():
opt_records = []
for o in options:
record = o.get_help_record(ctx)
if record is None:
continue
opt_records.append((o, record))
records.append(record)
opt_groups[group] = opt_records
first_columns = (r[0] for r in records)
border = min(COL_MAX, max(COL_MIN, *(len(col) for col in first_columns
if len(col) < COL_MAX)))
for opt_group, opt_records in opt_groups.items():
if not opt_records:
continue
formatter.write_heading(click.style(opt_group, bold=True))
formatter.indent()
padded_border = border + formatter.current_indent
for opt, record in opt_records:
self.write_option(ctx, formatter, opt, record, padded_border)
formatter.dedent()
# Modified from original:
# https://github.com/pallets/click/blob
# /c6042bf2607c5be22b1efef2e42a94ffd281434c/click/core.py#L1056
# Copyright (c) 2014 by the Pallets team.
commands = []
for subcommand in self.list_commands(ctx):
cmd = self.get_command(ctx, subcommand)
# What is this, the tool lied about a command. Ignore it
if cmd is None:
continue
if cmd.hidden:
continue
commands.append((subcommand, cmd))
# allow for 3 times the default spacing
if len(commands):
limit = formatter.width - 6 - max(len(cmd[0]) for cmd in commands)
rows = []
for subcommand, cmd in commands:
help = cmd.get_short_help_str(limit)
rows.append((CONFIG.cfg_style('command', subcommand), help))
if rows:
with formatter.section(click.style('Commands', bold=True)):
formatter.write_dl(rows)