diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ee0f0b..369ed1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ New features: Miscellaneous: * Add complete and working support for `toml` configuration files +* Handle `--verbosity 0` or `-v 0` correctly to not print anything from the linter * Add code coverage to the linter * Renamed `master` branch to `main` diff --git a/django_migration_linter/management/commands/lintmigrations.py b/django_migration_linter/management/commands/lintmigrations.py index fec4fdf..289ac6a 100644 --- a/django_migration_linter/management/commands/lintmigrations.py +++ b/django_migration_linter/management/commands/lintmigrations.py @@ -138,6 +138,8 @@ class Command(BaseCommand): if options["verbosity"] > 1: logging.basicConfig(format="%(message)s", level=logging.DEBUG) + elif options["verbosity"] == 0: + logger.disabled = True else: logging.basicConfig(format="%(message)s") @@ -201,6 +203,7 @@ class Command(BaseCommand): exclude_migration_tests=config["exclude_migration_tests"], quiet=config["quiet"], warnings_as_errors=config["warnings_as_errors"], + no_output=options["verbosity"] == 0, ) linter.lint_all_migrations( app_label=options["app_label"], diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index c83a9ea..660e8df 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -57,6 +57,7 @@ class MigrationLinter(object): exclude_migration_tests=None, quiet=None, warnings_as_errors=False, + no_output=False, ): # Store parameters and options self.django_path = path @@ -74,6 +75,7 @@ class MigrationLinter(object): self.only_unapplied_migrations = only_unapplied_migrations self.quiet = quiet or [] self.warnings_as_errors = warnings_as_errors + self.no_output = no_output # Initialise counters self.reset_counters() @@ -248,7 +250,8 @@ class MigrationLinter(object): def print_linting_msg(self, app_label, migration_name, msg, lint_result): if lint_result.value in self.quiet: return - print("({0}, {1})... {2}".format(app_label, migration_name, msg)) + if not self.no_output: + print("({0}, {1})... {2}".format(app_label, migration_name, msg)) def print_errors(self, errors): if MessageType.ERROR.value in self.quiet: @@ -260,7 +263,8 @@ class MigrationLinter(object): if err.get("column"): error_str += ", column: {0}".format(err["column"]) error_str += ")" - print(error_str) + if not self.no_output: + print(error_str) def print_warnings(self, warnings): if MessageType.WARNING.value in self.quiet: @@ -268,10 +272,12 @@ class MigrationLinter(object): for warning_details in warnings: warn_str = "\t{}".format(warning_details["msg"]) - print(warn_str) + if not self.no_output: + print(warn_str) def print_summary(self): - print() + if self.no_output: + return print("*** Summary ***") print("Valid migrations: {}/{}".format(self.nb_valid, self.nb_total)) print("Erroneous migrations: {}/{}".format(self.nb_erroneous, self.nb_total))