Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/git_draft/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def _load_layouts() -> Mapping[str, str]:

class _Context(TypedDict):
prompt: Mapping[str, str]
program: PromptName
toolbox: Toolbox


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


Expand All @@ -185,7 +186,11 @@ def _load_prompt(
rel_path = Path(f"{name}.{_extension}")
assert env.loader, "No loader in environment"
template = env.loader.load(env, str(rel_path))
context: _Context = dict(prompt=_load_layouts(), toolbox=toolbox)
context: _Context = dict(
program=name,
prompt=_load_layouts(),
toolbox=toolbox
)
try:
module = template.make_module(vars=cast(dict, context))
except jinja2.TemplateError as exc:
Expand Down
2 changes: 1 addition & 1 deletion src/git_draft/prompts/add-docstrings.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Add docstrings to one or more public symbols

Usage:
add-docstrings [--path PATH] [--symbol SYMBOL]
{{ program }} [--path PATH] [--symbol SYMBOL]

Options:
--path PATH Path to (Python) file where docstrings should be added. If
Expand Down
2 changes: 1 addition & 1 deletion src/git_draft/prompts/add-test.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Add tests for a symbol

Usage:
add-test --symbol NAME [--src-path PATH] [--test-path PATH]
{{ program }} --symbol NAME [--src-path PATH] [--test-path PATH]

Options:
--symbol NAME Name of the symbol to be tested.
Expand Down