Hooks for typer CLIs.
Project description
TyperHook
Overview
Hook decorators to enhance Typer CLIs. Current hooks:
- defaultparams: adapted from GitHub user Antoine adm271828, shares parameters between typer commands
Installation
pip install typerhook
Quick Start
import typer
import typerhook
from typing import Annotated
app = typer.Typer()
def debug_params(
ctx: typer.Context,
debug: Annotated[bool, typer.Option(help="Enable debug mode")] = False,
verbose: Annotated[bool, typer.Option(help="Verbose output")] = False,
):
ctx.ensure_object(dict)
ctx.obj['debug'] = debug
ctx.obj['verbose'] = verbose
@app.command()
@typerhook.defaultparams(debug_params)
def hello(
ctx: typer.Context,
name: Annotated[str, typer.Option(help="Name to greet")] = "World"
):
debug_mode = ctx.obj.get('debug', False)
typer.echo(f"Hello {name}! Debug mode: {debug}; Verbose mode: {verbose}")
@app.command()
@typerhook.defaultparams(debug_params)
def bye(
ctx: typer.Context,
name: Annotated[str, typer.Option(help="Name to greet")] = "World"
):
debug = ctx.obj.get('debug', False)
verbose = ctx.obj.get('verbose', False)
typer.echo(f"Goodbye {name}! Debug mode: {debug}; Verbose mode: {verbose}")
if __name__ == "__main__":
app()
API Reference
defaultparams(extra: Callable, *, drop: Optional[Sequence[str]]=None)
Decorator factory that adds extra parameters to a Typer command.
Parameters:
extra: Function containing the extra parameters to injectdrop: List of parameter names to exclude from the final signature
License
MIT License - see LICENSE file for details.
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
typerhook-0.1.0.tar.gz
(8.6 kB
view details)
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 typerhook-0.1.0.tar.gz.
File metadata
- Download URL: typerhook-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df3ce0a9c09d463b1b450f11be91a225100568f04bcaac3097025e37baa7eb55
|
|
| MD5 |
214c410b08dafe6444bd9c35b9923fd9
|
|
| BLAKE2b-256 |
7aca73209203cacd383f65bea4d5518f57ca993f8ca8a4ecf78f81ed603a9b58
|
File details
Details for the file typerhook-0.1.0-py3-none-any.whl.
File metadata
- Download URL: typerhook-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43e9a17d07ee074340d100d209beb21f885c1af1f87fe9125474aef850b1b013
|
|
| MD5 |
cff5855e5801e33892982a5c23b5bc5a
|
|
| BLAKE2b-256 |
aacef55019ca4941e96d28591ce0eeb087f26954835ca9ba8bf4419a8a93fbd7
|