dnd-item-generator/dnd_item/cli.py

46 lines
1.1 KiB
Python
Raw Normal View History

2023-12-04 22:28:03 -08:00
import logging
import os
from pathlib import Path
2023-12-04 22:28:03 -08:00
import typer
from rich.logging import RichHandler
from rich.console import Console
# from rich.table import Table
2023-12-04 22:28:03 -08:00
from dnd_item.types import random_item
from dnd_item import five_e
2023-12-04 22:28:03 -08:00
app = typer.Typer()
app_state = {}
2023-12-04 22:28:03 -08:00
@app.callback()
def main():
debug = os.getenv("FANITEM_DEBUG", None)
logging.basicConfig(
format="%(name)s %(message)s",
level=logging.DEBUG if debug else logging.INFO,
handlers=[RichHandler(rich_tracebacks=True, tracebacks_suppress=[typer])],
)
logging.getLogger('markdown_it').setLevel(logging.ERROR)
app_state['data'] = Path(__file__).parent / Path("sources")
2023-12-04 22:28:03 -08:00
@app.command()
def item(count: int = typer.Option(1, help="The number of items to generate.")):
items = random_item(count)
console = Console()
for item in items:
console.print(f"{item['Name']} of {item['Enchantment Noun']} "
f"({item['Damage Dice']} {item['Damage Type']} + "
f"{item['Enchantment Damage']} {item['Enchantment Type']})")
@app.command()
def convert():
src = five_e.weapons()
print(src.as_yaml)