Skip to main content

Click callback for injecting option defaults from TOML files

Project description

click-config-file-injection-utils


Table of Contents


1. Introduction

Utilities for building Click CLIs that load option defaults from user-specified TOML files. The package exposes a single callback function, injectDefaultOptionsFromToml and the exception MissingToolSectionError.

The config options in the TOML file are injected as the default config options, which can be overwritten by any CLI-specified configs. If users don't specify corresponding configs from CLI, these TOML config options will be actually applied to the CLI tool.

2. Installation Instruction

pip install click-config-file-injection-utils

3. Usage

Here is how you can use it with Click:

import click
from click_config_file_injection_utils import injectDefaultOptionsFromToml


@click.command()
@click.option(
    '--config',
    callback=lambda ctx, param, value: injectDefaultOptionsFromToml(
        ctx,
        param,
        value,
        toolSectionName='demo',
    ),
)
@click.option('--count', default=1, show_default=True)
def cli(count: int, config: str | None) -> None:
    click.echo(f'count={count}')


if __name__ == '__main__':
    cli()

If the user runs cli --config pyproject.toml and that file contains [tool.demo] count = 5, the command prints count=5. Passing --count on the CLI still overrides the TOML value.

The helper mirrors the behavior currently used in the pydoclint CLI, but it can be reused by any Click application that maintains its configuration under a [tool.<name>] table.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

click_config_file_injection_utils-0.1.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file click_config_file_injection_utils-0.1.0.tar.gz.

File metadata

File hashes

Hashes for click_config_file_injection_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f2e32f0b3c5b24c3863a4744971561ae5ed3b3b1afe0f3ce7509d94b9c282fb
MD5 af367e65f3335f4a0e009bcf9be74a28
BLAKE2b-256 e5b1ff27878129e6394da45f5acf433c1acbfca6ea65575f5f9a21c38dd3497c

See more details on using hashes here.

File details

Details for the file click_config_file_injection_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for click_config_file_injection_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d6eb30bc27ec1c12d6c10df97726ba2cd7dea6df5e3536304c1d0a46753c45b
MD5 29afe113d817011fb44378e2804f4672
BLAKE2b-256 a27a21e73cb5a68eb9bb5c886194903518dc4fc0998980f8ef65ece94afe207b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page