From 2241b1a3a2f4e955ec135d85cb5d5df01d676c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Mon, 13 Jan 2020 10:01:56 +0100 Subject: [PATCH] Replace django-subcommand2 by custom code --- modoboa/admin/management/commands/modo.py | 30 ++++++++++++++++++++--- requirements.txt | 1 - 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/modoboa/admin/management/commands/modo.py b/modoboa/admin/management/commands/modo.py index 94c7e6482..295b09062 100644 --- a/modoboa/admin/management/commands/modo.py +++ b/modoboa/admin/management/commands/modo.py @@ -1,6 +1,6 @@ """Modoboa main management command.""" -from subcommand.base import SubcommandCommand +from django.core.management.base import BaseCommand from .subcommands._export import ExportCommand from .subcommands._import import ImportCommand @@ -9,13 +9,13 @@ from .subcommands._mx import CheckMXRecords from .subcommands._repair import Repair -class Command(SubcommandCommand): +class Command(BaseCommand): """Top management command for modoboa. $ python manage.py modo """ - help = "Modoboa top management command." # NOQA:A003 + help = "Modoboa top management command." subcommands = { "export": ExportCommand, @@ -24,3 +24,27 @@ class Command(SubcommandCommand): "manage_dkim_keys": ManageDKIMKeys, "repair": Repair, } + + def add_arguments(self, parser): + subparsers = parser.add_subparsers( + dest='subcommand', title='subcommands' + ) + # required argument is added in Python 3.7 + subparsers.required = True + + for command_name, command_class in self.subcommands.items(): + command = command_class(self.stdout, self.stderr) + command.style = self.style + + subparser = subparsers.add_parser( + command_name, help=command_class.help + ) + # This is needed to output console friendly errors + subparser.called_from_command_line = self._called_from_command_line + + command.add_arguments(subparser) + + subparser.set_defaults(command=command) + + def execute(self, *args, **options): + return options.pop('command').execute(*args, **options) diff --git a/requirements.txt b/requirements.txt index f61b2dc60..f41b24baa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ django>=2.0,<2.1 django-braces==1.14.0 django-ckeditor==5.8.0 django-reversion==3.0.5 -django-subcommand2==0.1.1 django-xforwardedfor-middleware==2.0 dj-database-url