Skip to content

Commit

Permalink
[BugFix] Overwrite create_parser to avoid conflict when redeclaring v…
Browse files Browse the repository at this point in the history
…erbosity. (#10)

* feat(release_management): Overwrite create_parser to add the correct verbosity instead of conflicting with parent declaration.

* feat(setup): Bump version to 0.3.3.

* chore(release_management): Apply black.
  • Loading branch information
Gabriel-Fontenelle authored Apr 26, 2022
1 parent bc4422e commit eea5de7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
61 changes: 50 additions & 11 deletions migrations_mgmt_cmds/management/commands/release_management.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from os.path import join
from os.path import join, basename
from django.core.management.base import BaseCommand
from django.conf import settings
from django.utils.module_loading import import_string
from django.core.management.base import CommandParser, DjangoHelpFormatter

from migrations_mgmt_cmds.storage import migrations_releases_storage

Expand All @@ -19,6 +20,54 @@ class Command(BaseCommand):
help = "Manage release files."
sorted_files_by_date = None

def create_parser(self, prog_name, subcommand, **kwargs):
"""
Create and return the ``ArgumentParser`` which will be used to
parse the arguments to this command.
"""
parser = CommandParser(
prog="%s %s" % (basename(prog_name), subcommand),
description=self.help or None,
formatter_class=DjangoHelpFormatter,
missing_args_message=getattr(self, "missing_args_message", None),
called_from_command_line=getattr(self, "_called_from_command_line", None),
**kwargs,
)
parser.add_argument(
"--settings",
help=(
"The Python path to a settings module, e.g. "
'"myproject.settings.main". If this isn\'t provided, the '
"DJANGO_SETTINGS_MODULE environment variable will be used."
),
)
parser.add_argument(
"--pythonpath",
help='A directory to add to the Python path, e.g. "/home/djangoprojects/">',
)
parser.add_argument(
"--no-color",
action="store_true",
help="Don't colorize the command output.",
)
parser.add_argument(
"--force-color",
action="store_true",
help="Force colorization of the command output.",
)
parser.add_argument(
"-v",
"--verbosity",
action="store",
dest="verbosity",
default=2,
type=int,
choices=[0, 1, 2],
help="Verbosity level; 0=no output, 1=minimal output, 2=normal output",
)
self.add_arguments(parser)
return parser

def add_arguments(self, parser):
"""
Method to add arguments to be parsed by terminal (command line).
Expand Down Expand Up @@ -57,16 +106,6 @@ def add_arguments(self, parser):
default=None,
help="Nominates the release file's path to permanent delete it.",
)
parser.add_argument(
"-v",
"--verbosity",
action="store",
dest="verbosity",
default=2,
type=int,
choices=[0, 1, 2],
help="Verbosity level; 0=no output, 1=minimal output, 2=normal output",
)

def get_files_list(self, recursive=False, path=""):
files_list = []
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-migrations-mgmt
version = 0.3.2
version = 0.3.3
description = A Django management commands to help on migrations deployment rollbacks.
url = https://github.com/italux/django-migrations-mgmt/
author = Italo Santos
Expand Down

0 comments on commit eea5de7

Please sign in to comment.