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


Python click.core方法代码示例

本文整理汇总了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(),
        ) 
开发者ID:fetchai,项目名称:agents-aea,代码行数:14,代码来源:cli.py

示例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. 
开发者ID:qiime2,项目名称:q2cli,代码行数:15,代码来源:command.py

示例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. 
开发者ID:qiime2,项目名称:q2cli,代码行数:10,代码来源:command.py

示例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)) 
开发者ID:qiime2,项目名称:q2cli,代码行数:8,代码来源:command.py

示例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 
开发者ID:qiime2,项目名称:q2cli,代码行数:50,代码来源:command.py

示例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) 
开发者ID:qiime2,项目名称:q2cli,代码行数:57,代码来源:command.py


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