Пример #1
0
def common_decorator(f):
    @click.option(
        "-o",
        "--output-dir",
        "--output--directory",
        "output",
        default=".",
        type=click.Path(),
        # fmt: off
        help="Target download directory."
             "Also creates if the directory doesn't exist.",
        # fmt: on
    )
    @click.option(
        "-j", "--jobs", default=4, type=int, help="Number of concurrent jobs."
    )
    @click.option(
        "-t",
        "--type",
        type=click.Choice(["sample", "file", "preview"]),
        default="file",
        help="Quality of the image.",
    )
    @click.pass_context
    def new_func(ctx, *args, **kwargs):
        return ctx.invoke(f, ctx, *args, **kwargs)

    return update_wrapper(new_func, f)
Пример #2
0
def test_multiple_envvar(runner):
    @click.command()
    @click.option('--arg', multiple=True)
    def cmd(arg):
        click.echo('|'.join(arg))

    result = runner.invoke(cmd, [],
                           auto_envvar_prefix='TEST',
                           env={'TEST_ARG': 'foo bar baz'})
    assert not result.exception
    assert result.output == 'foo|bar|baz\n'

    @click.command()
    @click.option('--arg', multiple=True, envvar='X')
    def cmd(arg):
        click.echo('|'.join(arg))

    result = runner.invoke(cmd, [], env={'X': 'foo bar baz'})
    assert not result.exception
    assert result.output == 'foo|bar|baz\n'

    @click.command()
    @click.option('--arg', multiple=True, type=click.Path())
    def cmd(arg):
        click.echo('|'.join(arg))

    result = runner.invoke(cmd, [],
                           auto_envvar_prefix='TEST',
                           env={'TEST_ARG': 'foo%sbar' % os.path.pathsep})
    assert not result.exception
    assert result.output == 'foo|bar\n'
Пример #3
0
def test_option_help_preserve_paragraphs(runner):
    @click.command()
    @click.option(
        "-C",
        "--config",
        type=click.Path(),
        help="""Configuration file to use.

        If not given, the environment variable CONFIG_FILE is consulted
        and used if set. If neither are given, a default configuration
        file is loaded.""",
    )
    def cmd(config):
        pass

    result = runner.invoke(cmd, ["--help"])
    assert result.exit_code == 0
    i = " " * 21
    assert ("  -C, --config PATH  Configuration file to use.\n"
            f"{i}\n"
            f"{i}If not given, the environment variable CONFIG_FILE is\n"
            f"{i}consulted and used if set. If neither are given, a default\n"
            f"{i}configuration file is loaded.") in result.output
Пример #4
0
        cards.append({
            "id": card_id,
            "img": img_url,
            "title": title,
            "stack": stack
        })

    q = pq(html)
    q(".pageContent > .container > .row").find(".single-team").each(
        parse_single_card)

    return cards


@click.command()
@click.option("--file", "file_name", default="cards.json", type=click.Path())
@click.option("--rewrite", is_flag=True)
async def fetch(file_name, rewrite):
    if not Path(file_name).exists() or rewrite:
        async with httpx.AsyncClient() as client:
            with jsonstreams.Stream(jsonstreams.Type.object,
                                    filename=file_name,
                                    indent=2,
                                    pretty=True) as file_stream:
                with file_stream.subarray("cards") as cards:
                    for stack, url in STACKS.items():
                        console.print(f"Fetching {stack}")
                        response = await client.get(url)
                        pages = int(get_pages(response.text))
                        for page in range(1, pages + 1):
                            page_url = f"{url}?page={page}"