Migrate all commands to use 'typer' framework
This commit is contained in:
		
							parent
							
								
									d819d833af
								
							
						
					
					
						commit
						8287f02793
					
				
					 2 changed files with 52 additions and 54 deletions
				
			
		| 
						 | 
				
			
			@ -3,59 +3,68 @@
 | 
			
		|||
Rattail Demo Commands
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import sys
 | 
			
		||||
import typer
 | 
			
		||||
 | 
			
		||||
from rattail import commands
 | 
			
		||||
from rattail_demo import __version__
 | 
			
		||||
from rattail.commands.typer import (typer_callback, typer_get_runas_user,
 | 
			
		||||
                                    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:])
 | 
			
		||||
    cmd = Command()
 | 
			
		||||
    cmd.run(*args)
 | 
			
		||||
    config = ctx.parent.rattail_config
 | 
			
		||||
    progress = ctx.parent.rattail_progress
 | 
			
		||||
    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):
 | 
			
		||||
    """
 | 
			
		||||
    Main command for Rattail Demo
 | 
			
		||||
    """
 | 
			
		||||
    name = 'rattail-demo'
 | 
			
		||||
    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):
 | 
			
		||||
@rattail_demo_typer.command()
 | 
			
		||||
@importer_command
 | 
			
		||||
def import_self(
 | 
			
		||||
        ctx: typer.Context,
 | 
			
		||||
        **kwargs
 | 
			
		||||
):
 | 
			
		||||
    """
 | 
			
		||||
    Update "cascading" Rattail data based on "core" Rattail data
 | 
			
		||||
    """
 | 
			
		||||
    name = 'import-self'
 | 
			
		||||
    description = __doc__.strip()
 | 
			
		||||
    handler_spec = 'rattail_demo.importing.local:FromRattailDemoToSelf'
 | 
			
		||||
    config = ctx.parent.rattail_config
 | 
			
		||||
    progress = ctx.parent.rattail_progress
 | 
			
		||||
    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
 | 
			
		||||
    """
 | 
			
		||||
    name = 'install'
 | 
			
		||||
    description = __doc__.strip()
 | 
			
		||||
    from rattail.install import InstallHandler
 | 
			
		||||
 | 
			
		||||
    # nb. these must be explicitly set b/c config is not available
 | 
			
		||||
    # when running normally, e.g. `rattail-demo -n install`
 | 
			
		||||
    app_title = "Rattail Demo"
 | 
			
		||||
    app_package = 'rattail_demo'
 | 
			
		||||
    app_eggname = 'rattail_demo'
 | 
			
		||||
    app_pypiname = 'rattail-demo'
 | 
			
		||||
    config = ctx.parent.rattail_config
 | 
			
		||||
    handler = InstallHandler(config,
 | 
			
		||||
                             app_title="Rattail Demo",
 | 
			
		||||
                             app_package='rattail_demo',
 | 
			
		||||
                             app_eggname='rattail_demo',
 | 
			
		||||
                             app_pypiname='rattail_demo')
 | 
			
		||||
    handler.run()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										17
									
								
								setup.cfg
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								setup.cfg
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -38,23 +38,12 @@ packages = find:
 | 
			
		|||
 | 
			
		||||
[options.entry_points]
 | 
			
		||||
 | 
			
		||||
console_scripts =
 | 
			
		||||
        rattail-demo = rattail_demo.commands:rattail_demo_typer
 | 
			
		||||
 | 
			
		||||
paste.app_factory =
 | 
			
		||||
        main = rattail_demo.web.app:main
 | 
			
		||||
        webapi = rattail_demo.web.webapi:main
 | 
			
		||||
 | 
			
		||||
rattail.config.extensions =
 | 
			
		||||
        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…
	
	Add table
		Add a link
		
	
		Reference in a new issue