Metadata-Version: 2.4
Name: click-config-file-injection-utils
Version: 0.1.1
Summary: Click callback for injecting option defaults from TOML files
Author: jsh9
License: MIT License
        
        Copyright (c) 2025 jsh9
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/jsh9/click-config-file-injection-utils
Project-URL: Repository, https://github.com/jsh9/click-config-file-injection-utils
Keywords: cli,click,config,toml
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1
Dynamic: license-file

# click-config-file-injection-utils

<!--TOC-->

______________________________________________________________________

**Table of Contents**

- [1. Introduction](#1-introduction)
- [2. Installation Instruction](#2-installation-instruction)
- [3. Usage](#3-usage)

______________________________________________________________________

<!--TOC-->

## 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

```bash
pip install click-config-file-injection-utils
```

## 3. Usage

Here is how you can use it with `Click`:

```python
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.
