相关疑难解决方法(0)

python-click:格式化帮助文本

这个问题是关于点击包的:

  1. 帮助的长文本未按预期显示。
  2. /b也尝试过使用,但似乎影响不大。
  3. cmdpowershell相同的代码有不同的结果,为什么?

问题的屏幕截图

代码:

import click


def command_required_option_from_option(require_name, require_map):

    class CommandOptionRequiredClass(click.Command):

        def invoke(self, ctx):
            require = ctx.params[require_name]
            if require not in require_map:
                raise click.ClickException(
                    "Unexpected value for --'{}': {}".format(
                        require_name, require))
            if ctx.params[require_map[require]] is None:
                raise click.ClickException(
                    "With {}={} must specify option --{}".format(
                        require_name, require, require_map[require]))
            super(CommandOptionRequiredClass, self).invoke(ctx)

    return CommandOptionRequiredClass

required_options = {
    1: 'gs',  # generator_string
    2: 'nosp',  # number_of_sample_points
    3: 'nocp',  # number_of_center_points
}


@click.command(context_settings=dict(max_content_width=800), cls=command_required_option_from_option('doe', required_options))
@click.option('--input', required=True, type=click.Path(exists=True), metavar='FILE', …
Run Code Online (Sandbox Code Playgroud)

python command-line-interface python-click

5
推荐指数
1
解决办法
6848
查看次数