cmds.projects.CmdCreateFile: Add --field-separator option

List values in a rendered template are joined with a fixed separator of
",\n" (comma plus newline), and there is no way to change that. Templates
sometimes want a different separator, e.g. a plain newline or a single-line
comma-separated list.

Add a --field-separator option that controls how list values are joined
in the rendered output. %n expands to a newline, and the default remains
",\n" for both formats. render_tmpl() applies the separator to the rendered
template, while render_pyright() rejects any other value: the built-in
pyrightconfig.json template is a fixed JSON document, and no alternative
separator is supported for it.

Update the help output test expectation accordingly.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-09-12 19:33:54 +02:00
commit 1349665c39
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
4 changed files with 76 additions and 8 deletions

View file

@ -0,0 +1,8 @@
TOPDIR = ../../../../../../../..
include $(TOPDIR)/make/proj.mk
include $(JWBDIR)/make/py-run.mk
all:
test: run

View file

@ -0,0 +1,25 @@
from jw.pkg.cmds.projects.CmdCreateFile import CmdCreateFile
# __format_separator() is a private method that does not use self, so an
# uninitialised instance is a sufficient receiver for the bound method
inst = CmdCreateFile.__new__(CmdCreateFile)
fmt = getattr(inst, '_CmdCreateFile__format_separator')
# -- __format_separator --
# A None separator falls back to the format's default
assert fmt(None, ',\n') == ',\n'
# %n expands to a newline, wherever it appears in the separator
assert fmt('%n', ',\n') == '\n'
assert fmt(',%n', '\n') == ',\n'
assert fmt('a%n b', '') == 'a\n b'
# Several %n expand independently
assert fmt('%n%n', '') == '\n\n'
# Anything that is not %n passes through untouched
assert fmt('%', '') == '%'
assert fmt('%x', '') == '%x'
print('All CmdCreateFile tests passed')