From e04f03a76c7ffaff9f18d57e111b96e4e6fde774 Mon Sep 17 00:00:00 2001 From: QuentinN42 Date: Sat, 5 Feb 2022 11:40:17 +0100 Subject: [PATCH] feat: auto infer formats --- yamllint/cli.py | 5 ++--- yamllint/format.py | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/yamllint/cli.py b/yamllint/cli.py index d9e364e..7eb1cf1 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -26,7 +26,7 @@ from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint import linter from yamllint.config import YamlLintConfig, YamlLintConfigError from yamllint.linter import PROBLEM_LEVELS -from yamllint.format import show_all_problems +from yamllint.format import show_all_problems, Formater def find_files_recursively(items, conf): @@ -58,8 +58,7 @@ def run(argv=None): action='store', help='custom configuration (as YAML source)') parser.add_argument('-f', '--format', - choices=('parsable', 'standard', 'colored', 'github', - 'json', 'junitxml', 'codeclimate', 'auto'), + choices=[*Formater.get_formaters_names(), 'auto'], default='auto', help='format for parsing output') parser.add_argument('-s', '--strict', action='store_true', diff --git a/yamllint/format.py b/yamllint/format.py index 565e89b..a1eb294 100644 --- a/yamllint/format.py +++ b/yamllint/format.py @@ -52,6 +52,11 @@ class Formater(object): # the formater name name = '' + @classmethod + def get_formaters_names(cls): + """Return all formaters names.""" + return [f.name for f in cls.__subclasses__()] + @classmethod def get_formater(cls, name, no_warn): """Return a formater instance."""