diff --git a/changelogs/fragments/151-generate-output-format.yml b/changelogs/fragments/151-generate-output-format.yml new file mode 100644 index 0000000..06a9bb3 --- /dev/null +++ b/changelogs/fragments/151-generate-output-format.yml @@ -0,0 +1,2 @@ +bugfixes: + - "When multiple output formats are defined and ``antsibull-changelog generate`` is used with both ``--output`` and ``--output-format``, an error was displayed that ``--output-format`` must be specified (https://github.com/ansible-community/antsibull-changelog/issues/149, https://github.com/ansible-community/antsibull-changelog/pull/151)." diff --git a/src/antsibull_changelog/cli.py b/src/antsibull_changelog/cli.py index 30e115d..64e8cf3 100644 --- a/src/antsibull_changelog/cli.py +++ b/src/antsibull_changelog/cli.py @@ -750,7 +750,7 @@ def command_generate(args: Any) -> int: # pylint: disable=too-many-locals version=changes.latest_version, force_reload=args.reload_plugins, ) - if output and len(config.output_formats) > 1: + if output and len(config.output_formats) > 1 and not output_format: print( "When an explicit output path is specified and more than one output format" " is configured, you need to explicitly specify an output format" diff --git a/tests/functional/test_changelog_basic_collection.py b/tests/functional/test_changelog_basic_collection.py index 750392b..05bed45 100644 --- a/tests/functional/test_changelog_basic_collection.py +++ b/tests/functional/test_changelog_basic_collection.py @@ -143,6 +143,37 @@ def test_changelog_release_empty( # pylint: disable=redefined-outer-name ) assert collection_changelog.diff().unchanged + assert ( + collection_changelog.run_tool( + "generate", + ["-v", "--refresh", "--output", "extract.md", "--output-format", "md"], + ) + == 0 + ) + + diff = collection_changelog.diff() + assert diff.added_dirs == [] + assert diff.added_files == ["extract.md"] + assert diff.removed_dirs == [] + assert diff.removed_files == [] + assert diff.changed_files == [] + assert diff.file_contents["extract.md"].decode("utf-8") == ( + r"""# Ansible Release Notes + +**Topics** +- v1\.0\.0 + - Release Summary + + +## v1\.0\.0 + + +### Release Summary + +This is the first proper release\. +""" + ) + assert ( collection_changelog.run_tool( "release", ["-v", "--codename", "primetime", "--date", "2020-01-03"]