Add typer equivalents for rattail commands

This commit is contained in:
Lance Edgar 2024-05-16 20:04:52 -05:00
parent a80edf160b
commit 6ee6d5fea8
2 changed files with 28 additions and 5 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar # Copyright © 2010-2024 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -24,11 +24,31 @@
Rattail Commands for MailChimp integration Rattail Commands for MailChimp integration
""" """
from rattail import commands import typer
from rattail.util import load_object
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 ImportMailChimp(commands.ImportSubcommand): @rattail_typer.command()
@importer_command
def import_mailchimp(
ctx: typer.Context,
**kwargs
):
"""
Import data to Rattail, from MailChimp API
"""
config = ctx.parent.rattail_config
progress = ctx.parent.rattail_progress
handler = ImportCommandHandler(
config, import_handler_key='to_rattail.from_mailchimp.import')
kwargs['user'] = typer_get_runas_user(ctx)
handler.run(kwargs, progress=progress)
class ImportMailChimp(ImportSubcommand):
""" """
Import data to Rattail, from MailChimp API Import data to Rattail, from MailChimp API
""" """
@ -43,4 +63,4 @@ class ImportMailChimp(commands.ImportSubcommand):
else: else:
# just use default, for sake of cmd line help # just use default, for sake of cmd line help
spec = self.default_handler_spec spec = self.default_handler_spec
return load_object(spec) return self.app.load_object(spec)

View file

@ -38,5 +38,8 @@ zip_safe = False
rattail.subcommands = rattail.subcommands =
import-mailchimp = rattail_mailchimp.commands:ImportMailChimp import-mailchimp = rattail_mailchimp.commands:ImportMailChimp
rattail.typer_imports =
rattail_mailchimp = rattail_mailchimp.commands
rattail.emails = rattail.emails =
rattail_mailchimp = rattail_mailchimp.emails rattail_mailchimp = rattail_mailchimp.emails