improved CLI and added typing
This commit is contained in:
parent
5fb880a6e9
commit
99f479910c
112
npc/cli.py
112
npc/cli.py
|
@ -1,18 +1,98 @@
|
||||||
from npc.generator.base import generate_npc, npc_type
|
from npc.generator.base import generate_npc, npc_type
|
||||||
from npc import languages
|
from npc import languages
|
||||||
from rich import print
|
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import typer
|
import typer
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from rich import print
|
||||||
|
|
||||||
|
|
||||||
|
class Ancestry(str, Enum):
|
||||||
|
dragon = 'dragon'
|
||||||
|
drow = 'drow'
|
||||||
|
dwarf = 'dwarf'
|
||||||
|
elf = 'elf'
|
||||||
|
halfling = 'halfling'
|
||||||
|
halforc = 'halforc'
|
||||||
|
highelf = 'highelf'
|
||||||
|
highttiefling = 'hightiefling'
|
||||||
|
human = 'human'
|
||||||
|
tiefling = 'tiefling'
|
||||||
|
|
||||||
|
|
||||||
|
class Language(str, Enum):
|
||||||
|
abyssal = 'abyssal'
|
||||||
|
celestial = 'celestial'
|
||||||
|
common = 'commmon'
|
||||||
|
draconic = 'draconic'
|
||||||
|
dwarvish = 'dwarvish'
|
||||||
|
elven = 'elven'
|
||||||
|
gnomish = 'gnomish'
|
||||||
|
halfling = 'halfing'
|
||||||
|
infernal = 'infernal'
|
||||||
|
orcish = 'orcish'
|
||||||
|
undercommon = 'undercommon'
|
||||||
|
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def npc(ancestry=None, name=None, pronouns=None, title=None,
|
def npc(
|
||||||
nickname=None, whereabouts="Unknown", STR=None, DEX=None, CON=None,
|
ancestry: Ancestry = typer.Option(
|
||||||
INT=None, WIS=None, CHA=None, randomize=False):
|
None,
|
||||||
|
help='Derive NPC characteristics from a specific ancestry. Randomized if not specified.',
|
||||||
|
),
|
||||||
|
name: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC name. Randomized names are derived from ancestry',
|
||||||
|
),
|
||||||
|
pronouns: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC pronouns.',
|
||||||
|
),
|
||||||
|
title: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC title.',
|
||||||
|
),
|
||||||
|
nickname: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC nickname.',
|
||||||
|
),
|
||||||
|
whereabouts: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC whereabouts.',
|
||||||
|
),
|
||||||
|
STR: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC strength score.',
|
||||||
|
),
|
||||||
|
DEX: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC dexterity score.',
|
||||||
|
),
|
||||||
|
CON: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC constitution score.',
|
||||||
|
),
|
||||||
|
INT: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC intelligence score.',
|
||||||
|
),
|
||||||
|
WIS: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC wisdom score.',
|
||||||
|
),
|
||||||
|
CHA: str = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Specify the NPC charisma score.',
|
||||||
|
),
|
||||||
|
randomize: bool = typer.Option(
|
||||||
|
False,
|
||||||
|
help='If True, randomize default stat scores. If False, all stats are 10.'
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Generate a basic NPC.
|
Generate a basic NPC.
|
||||||
"""
|
"""
|
||||||
|
@ -34,14 +114,30 @@ def npc(ancestry=None, name=None, pronouns=None, title=None,
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def names(ancestry=None, count=1):
|
def names(ancestry: Ancestry = typer.Option(
|
||||||
|
None,
|
||||||
|
help='Derive NPC characteristics from a specific ancestry. Randomized if not specified.',
|
||||||
|
),
|
||||||
|
count: int = typer.Option(
|
||||||
|
1,
|
||||||
|
help='How many names to generate.'
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
for _ in range(int(count)):
|
for _ in range(int(count)):
|
||||||
print(npc_type(ancestry)().full_name)
|
print(npc_type(ancestry)().full_name)
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def text(language='common', words=50):
|
def text(
|
||||||
|
language: Language = typer.Option(
|
||||||
|
'common',
|
||||||
|
help='The language for which to generate text.',
|
||||||
|
),
|
||||||
|
count: int = typer.Argument(
|
||||||
|
50,
|
||||||
|
help='How many words to generate.'
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
mod = getattr(languages, language, None)
|
mod = getattr(languages, language, None)
|
||||||
if not mod:
|
if not mod:
|
||||||
print(f'Unsupported Language: {language}.')
|
print(f'Unsupported Language: {language}.')
|
||||||
|
@ -54,7 +150,7 @@ def text(language='common', words=50):
|
||||||
|
|
||||||
phrases = []
|
phrases = []
|
||||||
phrase = []
|
phrase = []
|
||||||
for word in [lang.word() for _ in range(int(words))]:
|
for word in [lang.word() for _ in range(int(count))]:
|
||||||
phrase.append(str(word))
|
phrase.append(str(word))
|
||||||
if len(phrase) >= random.randint(1, 12):
|
if len(phrase) >= random.randint(1, 12):
|
||||||
phrases.append(' '.join(phrase))
|
phrases.append(' '.join(phrase))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user