cmds.projects.CmdCreateFile: Add --field-* options and integration tests #100
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20260913-cmds-projects-cmdcreatefile-add-field-x-options-and-integration-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR extends CmdCreateFile with --field-keys and --field-separator options for controlling template key validation and list-value joining, and adds end-to-end integration tests covering the command's tmpl and pyright formats:
cmds.projects.CmdCreateFile: Add --field-keys option
The --field option accepts arbitrary KEY=VALUE pairs, inserting them into the rendered template output, but there is no way to declare which keys a template actually supports. Passing a key the template does not use goes unnoticed, and a template cannot offer optional fields that drop out of the output when not supplied.
Add a --field-keys option, a comma-separated list of the keys a template accepts. Passing a key via --field that is not in that list is an error, and keys from the list that are not passed are added with an empty value, so the respective field renders as empty and effectively drops out of the output.
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.
test/integration/projects/create-file: Add
CmdCreateFile renders a file from project metadata, yet nothing runs it end to end. The "tmpl" format substitutes --field values into template markers, and the "pyright" format computes extra paths from the jw run dependencies of a module. Both formats are untested, and so is the handling of missing templates, unknown --field keys, and malformed command-line arguments.
Add an integration test under test/integration/jw-pkg/projects that drives the command through the real CLI and diffs the rendered output against a reference. It covers single- and multi-value field substitution, the default and custom field separators including the %n newline escape, value quoting, and --field-keys filling in keys the caller omitted. The pyright case uses a relative topdir so the computed project paths stay relocatable. The error cases check that the command rejects a missing template name, an unknown template file, a --field key outside --field-keys, an unsupported pyright separator, and invalid --format and --field arguments with the expected message and exit status.