Migrate all commands to use 'typer' framework
This commit is contained in:
parent
d819d833af
commit
8287f02793
|
@ -3,59 +3,68 @@
|
||||||
Rattail Demo Commands
|
Rattail Demo Commands
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import typer
|
||||||
|
|
||||||
from rattail import commands
|
from rattail.commands.typer import (typer_callback, typer_get_runas_user,
|
||||||
from rattail_demo import __version__
|
importer_command, file_exporter_command)
|
||||||
|
from rattail.commands.importing import ImportCommandHandler
|
||||||
|
|
||||||
|
|
||||||
def main(*args):
|
# nb. this is the top-level command for titeship
|
||||||
|
rattail_demo_typer = typer.Typer(
|
||||||
|
callback=typer_callback,
|
||||||
|
help="Rattail Demo (custom Rattail system)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@rattail_demo_typer.command()
|
||||||
|
@file_exporter_command
|
||||||
|
def export_shopfoo(
|
||||||
|
ctx: typer.Context,
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Main entry point for Rattail Demo command system
|
Export data to the Harvest system
|
||||||
"""
|
"""
|
||||||
args = list(args or sys.argv[1:])
|
config = ctx.parent.rattail_config
|
||||||
cmd = Command()
|
progress = ctx.parent.rattail_progress
|
||||||
cmd.run(*args)
|
handler = ImportCommandHandler(
|
||||||
|
config, import_handler_spec='rattail_demo.shopfoo.importing.rattail:FromRattailToShopfoo')
|
||||||
|
kwargs['user'] = typer_get_runas_user(ctx)
|
||||||
|
kwargs['handler_kwargs'] = {'output_dir': kwargs['output_dir']}
|
||||||
|
handler.run(kwargs, progress=progress)
|
||||||
|
|
||||||
|
|
||||||
class Command(commands.Command):
|
@rattail_demo_typer.command()
|
||||||
"""
|
@importer_command
|
||||||
Main command for Rattail Demo
|
def import_self(
|
||||||
"""
|
ctx: typer.Context,
|
||||||
name = 'rattail-demo'
|
**kwargs
|
||||||
version = __version__
|
):
|
||||||
description = "Rattail Demo (custom Rattail system)"
|
|
||||||
long_description = ""
|
|
||||||
|
|
||||||
|
|
||||||
class ExportShopfoo(commands.ExportFileSubcommand):
|
|
||||||
"""
|
|
||||||
Export data to the Shopfoo system
|
|
||||||
"""
|
|
||||||
name = 'export-shopfoo'
|
|
||||||
description = __doc__.strip()
|
|
||||||
handler_spec = 'rattail_demo.shopfoo.importing.rattail:FromRattailToShopfoo'
|
|
||||||
|
|
||||||
|
|
||||||
class ImportSelf(commands.ImportSubcommand):
|
|
||||||
"""
|
"""
|
||||||
Update "cascading" Rattail data based on "core" Rattail data
|
Update "cascading" Rattail data based on "core" Rattail data
|
||||||
"""
|
"""
|
||||||
name = 'import-self'
|
config = ctx.parent.rattail_config
|
||||||
description = __doc__.strip()
|
progress = ctx.parent.rattail_progress
|
||||||
handler_spec = 'rattail_demo.importing.local:FromRattailDemoToSelf'
|
handler = ImportCommandHandler(
|
||||||
|
config, import_handler_spec='rattail_demo.importing.local:FromRattailDemoToSelf')
|
||||||
|
kwargs['user'] = typer_get_runas_user(ctx)
|
||||||
|
handler.run(kwargs, progress=progress)
|
||||||
|
|
||||||
|
|
||||||
class Install(commands.InstallSubcommand):
|
@rattail_demo_typer.command()
|
||||||
|
def install(
|
||||||
|
ctx: typer.Context,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Install the Rattail Demo app
|
Install the Rattail Demo 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. `rattail-demo -n install`
|
handler = InstallHandler(config,
|
||||||
app_title = "Rattail Demo"
|
app_title="Rattail Demo",
|
||||||
app_package = 'rattail_demo'
|
app_package='rattail_demo',
|
||||||
app_eggname = 'rattail_demo'
|
app_eggname='rattail_demo',
|
||||||
app_pypiname = 'rattail-demo'
|
app_pypiname='rattail_demo')
|
||||||
|
handler.run()
|
||||||
|
|
17
setup.cfg
17
setup.cfg
|
@ -38,23 +38,12 @@ packages = find:
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
|
|
||||||
|
console_scripts =
|
||||||
|
rattail-demo = rattail_demo.commands:rattail_demo_typer
|
||||||
|
|
||||||
paste.app_factory =
|
paste.app_factory =
|
||||||
main = rattail_demo.web.app:main
|
main = rattail_demo.web.app:main
|
||||||
webapi = rattail_demo.web.webapi:main
|
webapi = rattail_demo.web.webapi:main
|
||||||
|
|
||||||
rattail.config.extensions =
|
rattail.config.extensions =
|
||||||
rattail-demo = rattail_demo.config:DemoConfigExtension
|
rattail-demo = rattail_demo.config:DemoConfigExtension
|
||||||
|
|
||||||
console_scripts =
|
|
||||||
rattail-demo = rattail_demo.commands:main
|
|
||||||
|
|
||||||
rattail_demo.subcommands =
|
|
||||||
export-shopfoo = rattail_demo.commands:ExportShopfoo
|
|
||||||
import-self = rattail_demo.commands:ImportSelf
|
|
||||||
install = rattail_demo.commands:Install
|
|
||||||
|
|
||||||
# TODO: remove this legacy group once the above works okay
|
|
||||||
rattail_demo.commands =
|
|
||||||
export-shopfoo = rattail_demo.commands:ExportShopfoo
|
|
||||||
import-self = rattail_demo.commands:ImportSelf
|
|
||||||
install = rattail_demo.commands:Install
|
|
||||||
|
|
Loading…
Reference in a new issue