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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file click_config_file_injection_utils-0.1.1.tar.gz.
File metadata
- Download URL: click_config_file_injection_utils-0.1.1.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94c95f603534242e5f80e98390eb4063b3db29e6bfcb1b80831a92102884c7c3
|
|
| MD5 |
d4a25c5c999a225ed8bf46d725dab7d4
|
|
| BLAKE2b-256 |
b743407f3cfc912ed56e0e06b6f2a5a817d37d04ac76e755b99e647333b38abb
|
File details
Details for the file click_config_file_injection_utils-0.1.1-py3-none-any.whl.
File metadata
- Download URL: click_config_file_injection_utils-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1875cd8f59768365290560adffb71255173a9728b741d9c02603ca618b51376c
|
|
| MD5 |
5f040386348f6188dee987fc77655768
|
|
| BLAKE2b-256 |
4f8e44bbc4e125275afd8efed0f6cf6d2f265c7562898a2f348daba75afcdc08
|