Skip to content

Commit

Permalink
refactor: Prepare support for new output formats (styles) of the chec…
Browse files Browse the repository at this point in the history
…k command
  • Loading branch information
pawamoy committed Jan 16, 2024
1 parent d604282 commit f2ece1e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/griffe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def add_subparser(command: str, text: str, **kwargs: Any) -> argparse.ArgumentPa
help="Force disable colors in the output.",
)
check_options.add_argument("-v", "--verbose", action="store_true", help="Verbose output.")
formats = ("oneline", "verbose")
check_options.add_argument("-f", "--format", dest="style", choices=formats, default=None, help="Output format.")
add_common_options(check_parser)

return parser
Expand Down Expand Up @@ -403,6 +405,7 @@ def check(
allow_inspection: bool = True,
verbose: bool = False,
color: bool | None = None,
style: str | ExplanationStyle | None = None,
) -> int:
"""Load packages data and dump it as JSON.
Expand Down Expand Up @@ -470,7 +473,10 @@ def check(

colorama.deinit()
colorama.init(strip=color if color is None else not color)
style = ExplanationStyle.VERBOSE if verbose else ExplanationStyle.ONE_LINE
if style is None: # noqa: SIM108
style = ExplanationStyle.VERBOSE if verbose else ExplanationStyle.ONE_LINE
else:
style = ExplanationStyle(style)
for breakage in breakages:
print(breakage.explain(style=style), file=sys.stderr)

Expand Down
6 changes: 6 additions & 0 deletions src/griffe/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ def _explain_verbose(self) -> str:
lines.append("")
return "\n".join(lines)

def _explain_markdown(self) -> str:
return self._explain_oneline()

def _explain_github(self) -> str:
return self._explain_oneline()


class ParameterMovedBreakage(Breakage):
"""Specific breakage class for moved parameters."""
Expand Down
4 changes: 4 additions & 0 deletions src/griffe/enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class ExplanationStyle(enum.Enum):
"""Explanations on one-line."""
VERBOSE: str = "verbose"
"""Explanations on multiple lines."""
MARKDOWN: str = "markdown"
"""Explanations in Markdown, adapted to changelogs."""
GITHUB: str = "github"
"""Explanation as GitHub workflow commands warnings, adapted to CI."""


class BreakageKind(enum.Enum):
Expand Down

0 comments on commit f2ece1e

Please sign in to comment.