From cb62c1383c6a511cc150bc5a0118a8d86d55f358 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 16 May 2024 21:00:31 -0500 Subject: [PATCH] Add typer equivalents for `rattail` commands --- rattail_woocommerce/commands.py | 48 ++++++++++++++++++++++++++++++--- setup.cfg | 3 +++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/rattail_woocommerce/commands.py b/rattail_woocommerce/commands.py index 565ef34..cb547a1 100644 --- a/rattail_woocommerce/commands.py +++ b/rattail_woocommerce/commands.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -24,10 +24,50 @@ Rattail/WooCommerce Commands """ -from rattail import commands +import typer + +from rattail.commands import rattail_typer, ImportSubcommand +from rattail.commands.typer import importer_command, typer_get_runas_user +from rattail.commands.importing import ImportCommandHandler -class ExportWooCommerce(commands.ImportSubcommand): +@rattail_typer.command() +@importer_command +def export_woocommerce( + ctx: typer.Context, + **kwargs +): + """ + Export data to WooCommerce + """ + config = ctx.parent.rattail_config + progress = ctx.parent.rattail_progress + handler = ImportCommandHandler( + config, + import_handler_spec='rattail_woocommerce.woocommerce.importing.rattail:FromRattailToWooCommerce') + kwargs['user'] = typer_get_runas_user(ctx) + handler.run(kwargs, progress=progress) + + +@rattail_typer.command() +@importer_command +def import_woocommerce( + ctx: typer.Context, + **kwargs +): + """ + Import data from WooCommerce + """ + config = ctx.parent.rattail_config + progress = ctx.parent.rattail_progress + handler = ImportCommandHandler( + config, + import_handler_spec='rattail_woocommerce.importing.woocommerce:FromWooCommerceToRattail') + kwargs['user'] = typer_get_runas_user(ctx) + handler.run(kwargs, progress=progress) + + +class ExportWooCommerce(ImportSubcommand): """ Export data to WooCommerce """ @@ -36,7 +76,7 @@ class ExportWooCommerce(commands.ImportSubcommand): handler_spec = 'rattail_woocommerce.woocommerce.importing.rattail:FromRattailToWooCommerce' -class ImportWooCommerce(commands.ImportSubcommand): +class ImportWooCommerce(ImportSubcommand): """ Import data from WooCommerce """ diff --git a/setup.cfg b/setup.cfg index 4f89a6d..9092533 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,3 +38,6 @@ zip_safe = False rattail.commands = export-woocommerce = rattail_woocommerce.commands:ExportWooCommerce import-woocommerce = rattail_woocommerce.commands:ImportWooCommerce + +rattail.typer_imports = + rattail_woocommerce = rattail_woocommerce.commands