From 226c8750a3bf486a7828c7b66a1be18b0356f595 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 15 May 2024 15:10:35 -0500 Subject: [PATCH] Replace corporal commands with typer equivalents --- corporal/commands.py | 50 ++++++++++++++++++-------------------------- setup.cfg | 5 +---- 2 files changed, 21 insertions(+), 34 deletions(-) diff --git a/corporal/commands.py b/corporal/commands.py index d6667c6..f18cbf0 100644 --- a/corporal/commands.py +++ b/corporal/commands.py @@ -1,43 +1,33 @@ +# -*- coding: utf-8; -*- """ Corporal commands """ -import sys +import typer -from rattail import commands - -from corporal import __version__ +from rattail.commands.typer import typer_callback -def main(*args): - """ - Main entry point for Corporal command system - """ - args = list(args or sys.argv[1:]) - cmd = Command() - cmd.run(*args) +# nb. this is the top-level command for corporal +corporal_typer = typer.Typer( + callback=typer_callback, + help="Corporal (custom Rattail system)" +) -class Command(commands.Command): - """ - Main command for Corporal - """ - name = 'corporal' - version = __version__ - description = "Corporal (custom Rattail system)" - long_description = '' - - -class Install(commands.InstallSubcommand): +@corporal_typer.command() +def install( + ctx: typer.Context, +): """ Install the Corporal 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. `corporal -n install` - app_title = "Corporal" - app_package = 'corporal' - app_eggname = 'Corporal' - app_pypiname = 'Corporal' + config = ctx.parent.rattail_config + handler = InstallHandler(config, + app_title="Corporal", + app_package='corporal', + app_eggname='Corporal', + app_pypiname='Corporal') + handler.run() diff --git a/setup.cfg b/setup.cfg index 2da908f..113eeaa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,10 +40,7 @@ include_package_data = True [options.entry_points] console_scripts = - corporal = corporal.commands:main - -corporal.subcommands = - install = corporal.commands:Install + corporal = corporal.commands:corporal_typer paste.app_factory = main = corporal.web.app:main