Skip to content

Commit bb6945c

Browse files
authored
feat: add program prompt template variable (#89)
This protects against typos, and helps keep usage consistent with the template's name.
1 parent 4c10e93 commit bb6945c

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/git_draft/prompt.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def _load_layouts() -> Mapping[str, str]:
8484

8585
class _Context(TypedDict):
8686
prompt: Mapping[str, str]
87+
program: PromptName
8788
toolbox: Toolbox
8889

8990

@@ -167,7 +168,7 @@ def render(self, args: Sequence[str]) -> str:
167168
try:
168169
opts = docopt.docopt(self._doc, list(args))
169170
except docopt.DocoptExit as exc:
170-
raise ValueError(f"Invalid template arguments: {args}") from exc
171+
raise ValueError(f"Invalid template arguments\n{exc}") from exc
171172
return self._template.render({**self._context, "opts": opts})
172173

173174

@@ -185,7 +186,11 @@ def _load_prompt(
185186
rel_path = Path(f"{name}.{_extension}")
186187
assert env.loader, "No loader in environment"
187188
template = env.loader.load(env, str(rel_path))
188-
context: _Context = dict(prompt=_load_layouts(), toolbox=toolbox)
189+
context: _Context = dict(
190+
program=name,
191+
prompt=_load_layouts(),
192+
toolbox=toolbox
193+
)
189194
try:
190195
module = template.make_module(vars=cast(dict, context))
191196
except jinja2.TemplateError as exc:

src/git_draft/prompts/add-docstrings.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Add docstrings to one or more public symbols
55

66
Usage:
7-
add-docstrings [--path PATH] [--symbol SYMBOL]
7+
{{ program }} [--path PATH] [--symbol SYMBOL]
88

99
Options:
1010
--path PATH Path to (Python) file where docstrings should be added. If

src/git_draft/prompts/add-test.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Add tests for a symbol
55

66
Usage:
7-
add-test --symbol NAME [--src-path PATH] [--test-path PATH]
7+
{{ program }} --symbol NAME [--src-path PATH] [--test-path PATH]
88

99
Options:
1010
--symbol NAME Name of the symbol to be tested.

0 commit comments

Comments
 (0)