Skip to content

Commit

Permalink
Fix check for output format (#151)
Browse files Browse the repository at this point in the history
* Fix output-format condition.

* Add successful test.

* Reformat.
  • Loading branch information
felixfontein authored Feb 15, 2024
1 parent 912f715 commit 722e220
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/151-generate-output-format.yml
Original file line number Diff line number Diff line change
@@ -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)."
2 changes: 1 addition & 1 deletion src/antsibull_changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions tests/functional/test_changelog_basic_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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**
- <a href="#v1-0-0">v1\.0\.0</a>
- <a href="#release-summary">Release Summary</a>
<a id="v1-0-0"></a>
## v1\.0\.0
<a id="release-summary"></a>
### Release Summary
This is the first proper release\.
"""
)

assert (
collection_changelog.run_tool(
"release", ["-v", "--codename", "primetime", "--date", "2020-01-03"]
Expand Down

0 comments on commit 722e220

Please sign in to comment.