Skip to content

Commit

Permalink
fixup! Use KEY=VALUE instead of KEY VALUE as jinja-context param
Browse files Browse the repository at this point in the history
  • Loading branch information
chme committed Mar 23, 2024
1 parent c4ad73f commit 8ad26d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,9 @@ git-changelog -t path:changelog.md -j footer="Copyright 2024 My Company"
...or with the configuration option:

```toml
[jinja_context]
template = "path:changelog.md"

[jinja_context]
footer = "Copyright 2024 My Company"
```

Expand Down
8 changes: 4 additions & 4 deletions src/git_changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ def __call__(
attribute = getattr(namespace, self.dest)
if not isinstance(attribute, dict):
setattr(namespace, self.dest, {})
if isinstance(values, list) and len(values) == 2: # noqa: PLR2004
getattr(namespace, self.dest)[values[0]] = values[1]
if isinstance(values, str):
key, value = values.split("=", 1)
getattr(namespace, self.dest)[key] = value


providers: dict[str, type[ProviderRefParser]] = {
Expand Down Expand Up @@ -353,8 +354,7 @@ def get_parser() -> argparse.ArgumentParser:
"-j",
"--jinja-context",
action=_ParseDictAction,
metavar=("KEY", "VALUE"),
nargs=2,
metavar="KEY=VALUE",
dest="jinja_context",
help="Pass additional key/value pairs to the template. Option can be used multiple times. "
"The key/value pairs are accessible as 'jinja_context' in the template.",
Expand Down
19 changes: 10 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os
import sys
from textwrap import dedent
from typing import TYPE_CHECKING, Any, Iterator

import pytest
Expand Down Expand Up @@ -224,11 +225,13 @@ def test_jinja_context(repo: GitRepo) -> None:
repo: Temporary Git repository (fixture).
"""
repo.path.joinpath("conf.toml").write_text(
"""[jinja_context]
k1 = "ignored"
k2 = "v2"
k3 = "v3"
""".lstrip(),
dedent(
"""[jinja_context]
k1 = "ignored"
k2 = "v2"
k3 = "v3"
""",
),
)

template = repo.path.joinpath(".custom_template.md.jinja")
Expand All @@ -243,11 +246,9 @@ def test_jinja_context(repo: GitRepo) -> None:
"-t",
f"path:{template}",
"--jinja-context",
"k1",
"v1",
"k1=v1",
"-j",
"k3",
"v3",
"k3=v3",
str(repo.path),
],
)
Expand Down

0 comments on commit 8ad26d4

Please sign in to comment.