Skip to content

Commit

Permalink
cli: add render command stub
Browse files Browse the repository at this point in the history
See: #5
  • Loading branch information
NicolasT committed Feb 2, 2021
1 parent bdbfea7 commit db1c76a
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 22 deletions.
101 changes: 79 additions & 22 deletions changelog_binder/cli.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,96 @@
import click

import changelog_binder.types


@click.group()
def main():
"""Main entry-point of the changelog-binder tool"""


def with_list_options(obj):
decorators = [
click.option(
"--to",
metavar="VERSION",
help="List all fragments up to the given version",
),
click.option(
"--from",
"from_",
metavar="VERSION",
help=" ".join(
[
"List all fragments from the given version and up to",
"either HEAD or the version passed using the '--to'",
"argument",
]
),
),
click.option(
"--in",
"in_",
metavar="VERSION",
help=" ".join(
[
"List all fragments included in the given version,",
"and not in its preceding version",
]
),
),
]

for decorator in decorators:
obj = decorator(obj)

return obj


@main.command()
@with_list_options
def list(in_, from_, to):
"""List fragments that will be rendered"""
raise NotImplementedError


@main.command()
@with_list_options
@click.option(
"--in",
"in_",
metavar="VERSION",
help=" ".join(
[
"List all fragments included in the given version,",
"and not in its preceding version",
]
),
"--release-notes",
"release_notes",
is_flag=True,
help="Only render fragments tagged as release notes entries",
)
@click.option(
"--from",
"from_",
metavar="VERSION",
help=" ".join(
[
"List all fragments from the given version and up to either HEAD",
"or the version passed using the '--to' argument",
]
"--kind",
"kinds",
type=click.Choice(
kind.name.lower() for kind in changelog_binder.types.Kind
),
multiple=True,
help="Only render fragments of given kind(s)",
)
@click.option(
"--to",
metavar="VERSION",
help="List all fragments up to the given version",
"--epic",
"epics",
multiple=True,
help="Only render fragments of given epic(s)",
)
def list(in_, from_, to):
"""List fragments that will be rendered"""
@click.option(
"--no-epic",
"no_epic",
is_flag=True,
help="Only render fragments without specified epic",
)
@click.option(
"-o",
"--output",
type=click.Choice(
fmt.name.lower() for fmt in changelog_binder.types.OutputFormat
),
default="restructuredtext",
help="Output format",
)
def render(in_, from_, to, release_notes, kinds, epics, no_epic, output):
"""Render the changelog from fragments"""
raise NotImplementedError
15 changes: 15 additions & 0 deletions changelog_binder/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import enum


class Kind(enum.Enum):
"""Kind (of change) of a fragment"""

FEATURE = enum.auto()
BUGFIX = enum.auto()
IMPROVEMENT = enum.auto()


class OutputFormat(enum.Enum):
"""Output format the tool can generate"""

RESTRUCTUREDTEXT = enum.auto()
6 changes: 6 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ def test_list_from():
runner = CliRunner()
result = runner.invoke(cli.main, ["list", "--from", "0.1.0"])
assert result.exit_code == 1


def test_render():
runner = CliRunner()
result = runner.invoke(cli.main, ["render"])
assert result.exit_code == 1
Empty file added tests/test_types.py
Empty file.

0 comments on commit db1c76a

Please sign in to comment.