Skip to content

Commit 08264af

Browse files
authored
Made formatting cli option more consistent (#1404)
- Quiet formatter is not triggered with -f quiet - Allow combining -q with various formatters that can now change their behaviors. - When a calling with `-p -q`, we no longer print the full message
1 parent 1b9e21e commit 08264af

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/ansiblelint/app.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def choose_formatter_factory(
6868
) -> Type[formatters.BaseFormatter]:
6969
"""Select an output formatter based on the incoming command line arguments."""
7070
r: Type[formatters.BaseFormatter] = formatters.Formatter
71-
if options_list.quiet:
71+
if options_list.format == 'quiet':
7272
r = formatters.QuietFormatter
73-
elif options_list.parseable:
73+
elif options_list.parseable or options_list.format == 'pep8':
7474
r = formatters.ParseableFormatter
7575
elif options_list.parseable_severity:
7676
r = formatters.ParseableSeverityFormatter

src/ansiblelint/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_cli_parser() -> argparse.ArgumentParser:
131131
'-f',
132132
dest='format',
133133
default='rich',
134-
choices=['rich', 'plain', 'rst', 'codeclimate'],
134+
choices=['rich', 'plain', 'rst', 'codeclimate', 'quiet', 'pep8'],
135135
help="Format used rules output, (default: %(default)s)",
136136
)
137137
parser.add_argument(
@@ -146,7 +146,7 @@ def get_cli_parser() -> argparse.ArgumentParser:
146146
dest='parseable',
147147
default=False,
148148
action='store_true',
149-
help="parseable output in the format of pep8",
149+
help="parseable output, same as '-f pep8'",
150150
)
151151
parser.add_argument(
152152
'--parseable-severity',

src/ansiblelint/formatters/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import rich
99

10+
from ansiblelint.config import options
11+
1012
if TYPE_CHECKING:
1113
from ansiblelint.errors import MatchError
1214

@@ -84,8 +86,12 @@ class ParseableFormatter(BaseFormatter):
8486
def format(self, match: "MatchError") -> str:
8587
result = (
8688
f"[filename]{self._format_path(match.filename or '')}[/]:{match.position}: "
87-
f"[error_code]{match.rule.id}[/] [dim]{self.escape(match.message)}[/]"
89+
f"[error_code]{match.rule.id}[/]"
8890
)
91+
92+
if not options.quiet:
93+
result += f" [dim]{match.message}[/]"
94+
8995
if match.tag:
9096
result += f" [dim][error_code]({match.tag})[/][/]"
9197
return result

0 commit comments

Comments
 (0)