Skip to content

Commit b82d7dd

Browse files
Merge pull request #250 from Create-Python-App/fix/245-trailing-dir-after-template-url
fix(cli): preserve trailing dir after --template file:// URL (#245)
2 parents 5f78595 + fcc77d5 commit b82d7dd

6 files changed

Lines changed: 94 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.2.11 - 2026-07-23
4+
5+
### CLI / argv after template URL
6+
7+
- Do not treat `--template` / `-t` / other option *values* (e.g. `file://…`) as the project positional when expanding `--addons` / `--extend`. Fixes trailing `project_directory` being swallowed as an addon slug after a template URL (#245).
8+
39
## 0.2.10 - 2026-07-22
410

511
### CLI / UX

packages/create-awesome-python-app/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "create-awesome-python-app"
3-
version = "0.2.10"
3+
version = "0.2.11"
44
description = "Composable scaffolding CLI for production-ready Python apps"
55
readme = "README.md"
66
requires-python = ">=3.12"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Create Awesome Python App CLI."""
22

3-
__version__ = "0.2.10"
3+
__version__ = "0.2.11"

packages/create-awesome-python-app/src/create_awesome_python_app/cli.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ def _preprocess_fixture_argv(argv: list[str] | None = None) -> list[str]:
7373
return out
7474

7575

76+
# Flags that consume the following argv token as their value (not a positional).
77+
_VALUE_TAKING_FLAGS = frozenset(
78+
{
79+
"--template",
80+
"-t",
81+
"--set",
82+
"--pin",
83+
"--refresh",
84+
"--cache-dir",
85+
"--fixture",
86+
"--addons",
87+
"--extend",
88+
}
89+
)
90+
91+
7692
def _expand_variadic_option(argv: list[str], option: str) -> list[str]:
7793
"""Expand ``--addons a b`` into ``--addons a --addons b`` (CNA Commander parity).
7894
@@ -82,6 +98,9 @@ def _expand_variadic_option(argv: list[str], option: str) -> list[str]:
8298
When ``project_directory`` comes *after* options and no positional was seen
8399
yet, peel the final trailing token at EOS back as the directory so that
84100
``--addons a --addons b /tmp/app`` does not treat ``/tmp/app`` as an addon.
101+
102+
Option *values* (e.g. ``--template file://…``) must not set ``saw_positional``,
103+
or a trailing directory after ``--addons`` is never peeled (#245).
85104
"""
86105
out: list[str] = []
87106
i = 0
@@ -114,7 +133,9 @@ def _expand_variadic_option(argv: list[str], option: str) -> list[str]:
114133
i += 1
115134
continue
116135
if i > 0 and not arg.startswith("-"):
117-
saw_positional = True
136+
prev = out[-1] if out else ""
137+
if prev not in _VALUE_TAKING_FLAGS:
138+
saw_positional = True
118139
out.append(arg)
119140
i += 1
120141
return out

packages/create-awesome-python-app/tests/test_cli.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,69 @@ def test_expand_preserves_trailing_project_directory() -> None:
373373
]
374374

375375

376+
def test_expand_preserves_dir_after_template_file_url() -> None:
377+
"""``--template file://…`` must not block peeling a trailing project dir (#245)."""
378+
from create_awesome_python_app.cli import _preprocess_cli_argv
379+
380+
# Single addon URL + directory at EOS (scaffold-check / L3 shape).
381+
assert _preprocess_cli_argv(
382+
[
383+
"cpa",
384+
"--template",
385+
"file:///tmp/cpa?subdir=templates/fastapi-starter",
386+
"--no-interactive",
387+
"--no-install",
388+
"--addons",
389+
"file:///tmp/cpa?subdir=extensions/github-setup",
390+
"/tmp/my-api",
391+
]
392+
) == [
393+
"cpa",
394+
"--template",
395+
"file:///tmp/cpa?subdir=templates/fastapi-starter",
396+
"--no-interactive",
397+
"--no-install",
398+
"--addons",
399+
"file:///tmp/cpa?subdir=extensions/github-setup",
400+
"/tmp/my-api",
401+
]
402+
# Space-separated addons after a file:// template value.
403+
assert _preprocess_cli_argv(
404+
[
405+
"cpa",
406+
"--template",
407+
"file:///tmp/x",
408+
"--addons",
409+
"fastapi-docker",
410+
"github-setup",
411+
"/tmp/app",
412+
]
413+
) == [
414+
"cpa",
415+
"--template",
416+
"file:///tmp/x",
417+
"--addons",
418+
"fastapi-docker",
419+
"--addons",
420+
"github-setup",
421+
"/tmp/app",
422+
]
423+
# Short -t form.
424+
assert (
425+
_preprocess_cli_argv(
426+
[
427+
"cpa",
428+
"-t",
429+
"file:///tmp/x",
430+
"--addons",
431+
"github-setup",
432+
"scaffold-check",
433+
]
434+
)[-1]
435+
== "scaffold-check"
436+
)
437+
438+
376439
def test_space_separated_addons_after_project_directory(
377440
tmp_path: Path, monkeypatch
378441
) -> None:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)