This commit is contained in:
Waylon Walker 2023-05-15 11:37:32 -05:00
commit f3e79af444
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4
22 changed files with 1798 additions and 0 deletions

View file

View file

@ -0,0 +1,55 @@
import typer
from marvin_sw_text_adventure.cli.common import verbose_callback
from marvin_sw_text_adventure.console import console
from marvin_sw_text_adventure.cli.game import game_app
# from marvin_sw_text_adventure.cli.config import config_app
# from marvin_sw_text_adventure.cli.tui import tui_app
app = typer.Typer(
name="marvin_sw_text_adventure",
help="a text adventure game leveraging @askmarvinai",
)
app.add_typer(game_app)
# app.add_typer(config_app)
# app.add_typer(tui_app)
def version_callback(value: bool) -> None:
"""Callback function to print the version of the marvin-sw-text-adventure 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 marvin_sw_text_adventure.__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
if __name__ == "__main__":
typer.run(main)

View file

@ -0,0 +1,6 @@
from marvin_sw_text_adventure.console import console
def verbose_callback(value: bool) -> None:
if value:
console.quiet = False

View file

@ -0,0 +1,29 @@
from rich.console import Console
import typer
from marvin_sw_text_adventure.cli.common import verbose_callback
from marvin_sw_text_adventure.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)

View file

@ -0,0 +1,31 @@
from rich.console import Console
import typer
from marvin_sw_text_adventure.cli.common import verbose_callback
from marvin_sw_text_adventure.game import game as game_run
game_app = typer.Typer()
@game_app.callback()
def game(
verbose: bool = typer.Option(
False,
callback=verbose_callback,
help="show the log messages",
),
):
"game cli"
@game_app.command()
def run(
verbose: bool = typer.Option(
False,
callback=verbose_callback,
help="show the log messages",
),
):
from marvin_sw_text_adventure.console import console
console.log("Starting game")
game_run()

View file

@ -0,0 +1,18 @@
import typer
from marvin_sw_text_adventure.cli.common import verbose_callback
from marvin_sw_text_adventure.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()