Skip to content

Plugin option multi-value syntax silently mis-parses, and behaves differently from the Python port #5

@ultimatile

Description

@ultimatile

Summary

jtc config set accepts plugin-specific options like --tests, --git, --formatter, etc., each documented as taking KEY=VALUE pairs. There are three problems with how multiple pairs are accepted today:

  1. Comma-separated form silently mis-parses. --tests "aqua=true,project=true" does not error and does not get split; instead it produces a corrupt list value.
  2. Repeating the flag does not append. --tests aqua=true --tests project=true only keeps the last value — the earlier one is lost. The Python port (JuliaPkgTemplatesCLI) supported the repeat form, so this is a regression for users porting their muscle memory.
  3. The intended form (space-separated single string) is not documented anywhere user-visible. It only appears in an internal source comment.

The result is that the same intent (set two plugin keys at once) can produce three different and silently wrong configurations depending on which form a user types.

Reproduction

Using --config-file to avoid touching the global config:

# (1) Comma-separated form — accepted, but corrupt
$ julia --project=. -e 'using PkgTemplatesCommandLineInterface; PkgTemplatesCommandLineInterface.main(ARGS)' -- \
    config set --tests "aqua=true,project=true" --config-file /tmp/jtc-test.toml
[ Info: Configuration saved to /tmp/jtc-test.toml
Set default Tests.aqua: ["true", "project=true"]

Resulting TOML:

[default.Tests]
aqua = ["true", "project=true"]

Tests.aqua is a boolean option, but a list value was persisted.

# (2) Repeated flag — last value wins, earlier value is silently dropped
$ ... config set --tests aqua=true --tests project=true --config-file /tmp/jtc-test.toml
Set default Tests.project: true

Resulting TOML:

[default.Tests]
project = true

aqua=true is missing.

# (3) Space-separated single string — works correctly
$ ... config set --tests "aqua=true project=true" --config-file /tmp/jtc-test.toml
Set default Tests.project: true
Set default Tests.aqua: true

Resulting TOML:

[default.Tests]
aqua = true
project = true

Why users would type the broken forms

  • The help text for --tests (and every other plugin flag) only says Set <Plugin> plugin defaults (omit value to enable with defaults) with metavar KEY=VALUE. There is no example of how to provide multiple pairs.

  • The help text for --author does document two forms explicitly: Examples: --author 'A, B' or --author 'A' --author 'B'. Supports both single and multiple authors. Users naturally generalise this to plugin flags and try --tests "aqua=true,project=true" — which then mis-parses.

  • Users coming from the Python port (JuliaPkgTemplatesCLI) will try repeating --tests because that is the form that worked there.

  • The actual intended form — space-separated KEY=VALUEs in a single shell-quoted string — only appears in src/cli.jl:186 as an internal comment:

    # `argumentless_as_flag=true` matches the legacy `create` registration where
    # zero-arg plugins become bare flags. When false, every plugin accepts an
    # optional space-separated KEY=VALUE string (`--plugin` / `--plugin "k=v ..."`).
    

Suggested fixes

Pick any combination:

  1. Reject malformed values for known-scalar keys. Tests.aqua is a boolean — a list value should error out instead of being persisted.
  2. Document the supported form in the help text of every plugin flag, e.g. Multiple keys: --tests "aqua=true project=true".
  3. Also accept repeat and comma-separated forms, and normalise all three to the same internal representation. This matches what --author already trains users to expect, and avoids regressing users coming from the Python port.
  4. Echo a unified diff before saving and require confirmation when a previously-set scalar would be replaced by a list (or vice-versa). This would also catch (1) at runtime.
  5. Update the README to show at least one explicit example of setting multiple keys for a single plugin, in whatever form ends up being canonical.

Environment

  • Source: PkgTemplatesCommandLineInterface.jl (this repository), invoked via julia --project=. -e 'using PkgTemplatesCommandLineInterface; PkgTemplatesCommandLineInterface.main(ARGS)' -- ...
  • Verified against --config-file /tmp/jtc-test.toml to avoid touching the global config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions