diff --git a/changelog_binder/cli.py b/changelog_binder/cli.py index dda1412..e2e7970 100644 --- a/changelog_binder/cli.py +++ b/changelog_binder/cli.py @@ -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 diff --git a/changelog_binder/types.py b/changelog_binder/types.py new file mode 100644 index 0000000..51bd112 --- /dev/null +++ b/changelog_binder/types.py @@ -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() diff --git a/tests/test_cli.py b/tests/test_cli.py index 3e4658a..02ab9e0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 diff --git a/tests/test_types.py b/tests/test_types.py new file mode 100644 index 0000000..e69de29