init
This commit is contained in:
commit
de5030a381
20 changed files with 1660 additions and 0 deletions
0
pydantic_typer/cli/__init__.py
Normal file
0
pydantic_typer/cli/__init__.py
Normal file
62
pydantic_typer/cli/app.py
Normal file
62
pydantic_typer/cli/app.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import typer
|
||||
|
||||
from pydantic_typer import Person, expand_pydantic_args
|
||||
from pydantic_typer.cli.common import verbose_callback
|
||||
from pydantic_typer.cli.config import config_app
|
||||
from pydantic_typer.cli.tui import tui_app
|
||||
|
||||
app = typer.Typer(
|
||||
name="pydantic_typer",
|
||||
help="A rich terminal report for coveragepy.",
|
||||
)
|
||||
app.add_typer(config_app)
|
||||
app.add_typer(tui_app)
|
||||
|
||||
|
||||
def version_callback(value: bool) -> None:
|
||||
"""Callback function to print the version of the pydantic-typer package.
|
||||
|
||||
Args:
|
||||
value (bool): Boolean value to determine if the version should be printed.
|
||||
|
||||
Raises:
|
||||
typer.Exit: If the value is True, the version will be printed and the program will exit.
|
||||
|
||||
Example:
|
||||
version_callback(True)
|
||||
"""
|
||||
if value:
|
||||
from pydantic_typer.__about__ import __version__
|
||||
|
||||
typer.echo(f"{__version__}")
|
||||
raise typer.Exit()
|
||||
|
||||
|
||||
@app.callback()
|
||||
def main(
|
||||
version: bool = typer.Option(
|
||||
None,
|
||||
"--version",
|
||||
callback=version_callback,
|
||||
is_eager=True,
|
||||
),
|
||||
verbose: bool = typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
) -> None:
|
||||
return
|
||||
|
||||
|
||||
@app.command()
|
||||
@expand_pydantic_args
|
||||
def get_person(person: Person) -> Person:
|
||||
"""mydocstring"""
|
||||
from rich import print
|
||||
|
||||
print(person)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
typer.run(main)
|
||||
6
pydantic_typer/cli/common.py
Normal file
6
pydantic_typer/cli/common.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from pydantic_typer.console import console
|
||||
|
||||
|
||||
def verbose_callback(value: bool) -> None:
|
||||
if value:
|
||||
console.quiet = False
|
||||
29
pydantic_typer/cli/config.py
Normal file
29
pydantic_typer/cli/config.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from rich.console import Console
|
||||
import typer
|
||||
|
||||
from pydantic_typer.cli.common import verbose_callback
|
||||
from pydantic_typer.config import config as configuration
|
||||
|
||||
config_app = typer.Typer()
|
||||
|
||||
|
||||
@config_app.callback()
|
||||
def config(
|
||||
verbose: bool = typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
):
|
||||
"configuration cli"
|
||||
|
||||
|
||||
@config_app.command()
|
||||
def show(
|
||||
verbose: bool = typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
):
|
||||
Console().print(configuration)
|
||||
18
pydantic_typer/cli/tui.py
Normal file
18
pydantic_typer/cli/tui.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import typer
|
||||
|
||||
from pydantic_typer.cli.common import verbose_callback
|
||||
from pydantic_typer.tui.app import run_app
|
||||
|
||||
tui_app = typer.Typer()
|
||||
|
||||
|
||||
@tui_app.callback(invoke_without_command=True)
|
||||
def i(
|
||||
verbose: bool = typer.Option(
|
||||
False,
|
||||
callback=verbose_callback,
|
||||
help="show the log messages",
|
||||
),
|
||||
):
|
||||
"interactive tui"
|
||||
run_app()
|
||||
Loading…
Add table
Add a link
Reference in a new issue