Migrate commands to use 'typer' framework

This commit is contained in:
Lance Edgar 2024-05-15 16:07:10 -05:00
parent 8a6933c43e
commit af1757b66f
2 changed files with 22 additions and 35 deletions

View file

@ -26,6 +26,7 @@ install_requires =
mysql-connector-python mysql-connector-python
psycopg2 psycopg2
Tailbone Tailbone
typer
packages = find: packages = find:
include_package_data = True include_package_data = True
@ -41,7 +42,7 @@ locsms = luckysmores; rattail-luckysmores; tailbone-locsms
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
theo = theo.commands:main theo = theo.commands:theo_typer
rattail.config.extensions = rattail.config.extensions =
theo = theo.config:TheoConfig theo = theo.config:TheoConfig
@ -57,6 +58,3 @@ rattail.importing =
paste.app_factory = paste.app_factory =
main = theo.web.app:main main = theo.web.app:main
webapi = theo.web.webapi:main webapi = theo.web.webapi:main
theo.subcommands =
install = theo.commands:Install

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar # Copyright © 2010-2024 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,42 +24,31 @@
Theo commands Theo commands
""" """
import sys import typer
from rattail import commands from rattail.commands.typer import typer_callback
from theo import __version__
def main(*args): # nb. this is the top-level command for corporal
""" theo_typer = typer.Typer(
Main entry point for Theo command system callback=typer_callback,
""" help="Theo, the order system"
args = list(args or sys.argv[1:]) )
cmd = Command()
cmd.run(*args)
class Command(commands.Command): @theo_typer.command()
""" def install(
Main command for Theo ctx: typer.Context,
""" ):
name = 'theo'
version = __version__
description = "Theo, the order system"
long_description = ''
class Install(commands.InstallSubcommand):
""" """
Install the Theo app Install the Theo app
""" """
name = 'install' from rattail.install import InstallHandler
description = __doc__.strip()
# nb. these must be explicitly set b/c config is not available config = ctx.parent.rattail_config
# when running normally, e.g. `theo -n install` handler = InstallHandler(config,
app_title = "Theo" app_title="Theo",
app_package = 'theo' app_package='theo',
app_eggname = 'tailbone_theo' app_eggname='tailbone_theo',
app_pypiname = 'tailbone-theo' app_pypiname='tailbone-theo')
handler.run()