Skip to content

fix(docs): pin command-reference metavar format as a stable contract (#513)#517

Draft
padak wants to merge 1 commit into
mainfrom
claude/issue-513-pin-metavar-contract
Draft

fix(docs): pin command-reference metavar format as a stable contract (#513)#517
padak wants to merge 1 commit into
mainfrom
claude/issue-513-pin-metavar-contract

Conversation

@padak

@padak padak commented Jul 22, 2026

Copy link
Copy Markdown
Member

What

The release-asset command reference (scripts/gen_command_reference.py, consumed by help.keboola.com and the connection-docs freshness gate) rendered its option metavar column via Click's make_metavar(). That default is not stable across Click versions — it already drifted once: bare `TEXT` / `INTEGER` at v0.70.1 (Click 8.x), `<str>` / `<int>` at v0.72.0.

This PR pins the option metavar shape to a documented convention independent of the installed Click:

  • Derive from ParamType.name (a version-stable token: text/integer/float/path/choice) instead of make_metavar(), via a new _stable_option_metavar().
  • Value-taking options always render as a <...> span — <str>, <int>, <float>, <path>, and <a|b|c> for choices (literal case preserved, e.g. <admin|guest|readOnly|share>, since choice values are real CLI tokens). Flags carry no metavar span.
  • Author-set metavars are wrapped and lowercased (ALIAS<alias>).
  • The column contract is documented in the module header.
  • Positional arguments are unchanged — they render as `NAME` (positional) and are not part of the | `--flag` `<type>` | shape the downstream gate parses.

Why

The connection-docs freshness gate (keboola/connection-docs#1037, PRDCT-556) detects whether an option takes a value by matching /^<.*>$/ on the metavar span. That works today only because 0.72.0 happens to emit the <…> form. A future Typer/Click bump reverting to bare TEXT would silently make the checker misparse value-taking options, turning valid commands into false-positive "unknown command" errors and reddening the docs build on correct content. Pinning the format at the source makes the published asset a contract by intent, not by accident of the dependency version.

How it was tested

  • New TestMetavarContract in tests/test_gen_command_reference.py: asserts scalar types map to the documented <...> forms, choices preserve literal case, explicit metavars are wrapped/lowercased, every value option satisfies the <...> span contract, flags carry no span, no bare uppercase TEXT/INTEGER/PATH/FLOAT leaks onto an option row, and the documented scalar/choice forms are present in the generated asset. A Click/Typer bump that changes make_metavar() now fails CI here instead of downstream.
  • make check green (lint + format + changelog-check + typecheck + full suite: 4620 passed, 8 skipped).
  • Verified the generated reference: all option metavars are <...>-wrapped; no bare uppercase metavars remain.

Note: no version bump / changelog entry — this only stabilizes the generated asset's shape (already <str> in the last release), it does not change the CLI surface. The immediate mitigation on the consumer side (accept <str> | TEXT | [a|b]) is still recommended in the linked issue; this is the durable source-side fix.

Fixes #513

…513)

The release-asset reference (help.keboola.com, connection-docs freshness
gate) is a published contract, but its option metavar column was rendered
via Click's make_metavar(), whose default drifted between releases (bare
`TEXT`/`INTEGER` at Click 8.x vs `<str>`/`<int>` later). The downstream
connection-docs gate (keboola/connection-docs#1037) detects value-taking
options by matching /^<.*>$/ on the metavar span, so a future dependency
bump reverting to bare `TEXT` would silently break the docs build.

Derive option metavars from Click's version-stable `ParamType.name`
instead of `make_metavar()`: value-taking options always render as a
`<...>` span (`<str>`, `<int>`, `<path>`, `<a|b|c>` for choices with
literal case preserved), flags carry none. Document the column contract
in the module header and add tests that fail CI on a Click/Typer bump
that would change the shape, instead of letting the drift surface
downstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pin command-reference.md metavar format as a stable contract (docs gate depends on it)

1 participant