Skip to content

fix(cli): quote cobra defaults that KDL reads as booleans or numbers - #1595

Merged
jdx merged 1 commit into
mainfrom
claude/github-issue-1594-cdd1d4
Oct 29, 2026
Merged

jdx merged 1 commit into
mainfrom
claude/github-issue-1594-cdd1d4

Conversation

@jdx

@jdx jdx commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

The Cobra exporter wrote some flag defaults as bare KDL values, which usage rejects because defaults must be strings. A Cobra command with a true bool flag or a negative integer flag produced a spec that usage lint could not parse.

cmd.Flags().Bool("enabled", true, "Enable the feature")
cmd.Flags().Int("parallel", -1, "Maximum parallelism")

Before

flag --enabled help="Enable the feature" default=true
flag --parallel help="Maximum parallelism" default=-1 {
    arg <PARALLEL>
}

usage lint failed with "Expected identifier string" and "expected string".

After

flag --enabled help="Enable the feature" default="true"
flag --parallel help="Maximum parallelism" default="-1" {
    arg <PARALLEL>
}

The cause was needsQuoting in integrations/cobra/kdl.go, which only quoted values starting with a digit or containing certain punctuation. It now also quotes:

  • keyword-like values: true, false, null, inf, -inf, nan
  • signed numbers such as -1, +1 and -0.5
  • values containing [ or ]

Plain values such as json are still emitted bare, so existing output is unchanged.

Validation: a new Go test covers each case. I also generated a spec containing these defaults and ran it through usage lint from usage 7.1.3, which reported 0 errors. That round trip was a one-off check, not part of the test suite.

Fixes #1594

AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Generated configuration now preserves flag defaults that resemble numbers, boolean values, null, special numeric values, or bracketed content as strings. This prevents values such as "+1", "null", and "[a]" from being interpreted as something other than their intended text.

The Cobra exporter wrote some flag defaults as bare KDL values, so
`Bool("enabled", true)` produced `default=true` and `Int("parallel", -1)`
produced `default=-1`. Usage expects string defaults, so `usage lint`
rejected the generated spec.

needsQuoting now also quotes true/false/null/inf/-inf/nan, signed
numbers, and values containing brackets.

Fixes #1594

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Entire-Checkpoint: 01M64MA2XS7BMFE1WFRFEAW1M3
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 874f030f-20c9-4772-b020-e96be497c68c
Commits

Reviewing files that changed from the base of the PR and between 3c13054 and 920d2e8.

Files selected for processing: 2
  • integrations/cobra/cobra_usage_test.go
  • integrations/cobra/kdl.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The Cobra exporter now quotes generated flag defaults that resemble KDL keywords, signed numbers, or bracketed values. A test checks generated defaults for these cases.

Changes: Cobra default quoting

Layer / File(s) Summary
Quote non-identifier defaults
integrations/cobra/kdl.go, integrations/cobra/cobra_usage_test.go
needsQuoting now quotes signed numeric-looking values, KDL keywords, and values containing square brackets. The test checks quoted defaults for representative boolean, numeric, null-like, and bracketed values.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: thecodesmith

Merge Risk: Minimal · up to 920d2

No actionable merge-blocking risk was identified in the changed default-quoting behavior.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: quoting Cobra defaults that KDL would interpret as booleans or numbers.
Linked Issues check Passed Issue #1594 requires Cobra defaults such as boolean true and negative integer -1 to remain KDL strings. At the reviewed head, renderFlag passes single defaults through kdlQuote, and `needsQuot…
Out of Scope Changes check Passed The reviewed changes are limited to KDL quoting behavior in integrations/cobra/kdl.go and focused Cobra exporter tests in integrations/cobra/cobra_usage_test.go. The added bracket, keyword, and si…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

Issue #1594 requires Cobra defaults such as boolean true and negative integer -1 to remain KDL strings. At the reviewed head, renderFlag passes single defaults through kdlQuote, and needsQuoting quotes true, signed numeric values, and other KDL-sensitive values. TestDefaultsQuotedWhenNotIdentifiers verifies default="true", default="-1", and related cases. The existing json case remains bare in TestDefaultValues.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to KDL quoting behavior in integrations/cobra/kdl.go and focused Cobra exporter tests in integrations/cobra/cobra_usage_test.go. The added bracket, keyword, and signed-number checks support valid string serialization for the linked issue. No unrelated change is evidenced.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

The Cobra exporter now quotes defaults that cannot safely appear as bare KDL strings.

  • Cobra defaults that look like KDL values stay strings in generated specs.

Reviews (1) · Last reviewed commit: "fix(cli): quote cobra defaults that KDL ..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Instruction counts

benchmark trend instructions Δ wall (min) Δ
markdown ▂▃▁▂▂▃▂▂▃▂▂▂▃▂▁▂█▇▇ 266,862,411 → 266,849,406 -0.00% 47.18 → 46.82ms -0.76%
startup ▂▂▂▂▂▂▄▂▂▂▂▆▆▆▆▆█▁▇ 1,010,416 → 1,017,311 +0.68% 1.34 → 1.54ms +15.07%

No instruction-count regression above 1%.

Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run.

Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes.

Shadow comparison

Parsing mise use -g node@20 against a shadow of mise's committed spec.
Reported, not gated: the shadow grows as the derive learns to express more, so
what to watch is the ratio rather than either column.

framework stripped binary, bytes
usage 1249896
bpaf 2494640
clap 3100904
framework instructions, cold parse vs usage
usage 8295 —
clap 6313736 761x
bpaf 21909300 2641x
                                              min       p01       p10    median
usage-rs: argv -> struct                      762       763       767       780  ns
clap: build tree + parse -> struct        1234600   1238080   1247758   1266472  ns
bpaf: build parser + parse -> struct      3423229   3423229   3449920   3479816  ns

usage: argv -> struct                             749 ns      0.75 µs
clap: build tree + parse -> struct            1254599 ns   1254.60 µs
clap: parse -> struct, tree reused              49879 ns     49.88 µs
clap: build tree only                          745522 ns    745.52 µs

920d2e8a9dde vs ad1549d987d4 · measured on the runner, not pushed to the history.

@jdx
jdx merged commit 48f0d5e into main Oct 29, 2026
15 checks passed
@jdx
jdx deleted the claude/github-issue-1594-cdd1d4 branch October 29, 2026 20:30
mise-en-dev added a commit that referenced this pull request Oct 30, 2026
### 🐛 Bug Fixes

- **(cli)** quote cobra defaults that KDL reads as booleans or numbers
by [@jdx](https://github.com/jdx) in
[#1595](#1595)
- **(lib)** read a mounted script's spec despite a rejected env value,
and name the failing mount by [@jdx](https://github.com/jdx) in
[#1591](#1591)

### 🛡️ Security

- **(deps)** update jdx/packslip action to v1.11.0 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1597](#1597)

### 📦️ Dependency Updates

- update github actions by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1585](#1585)
- update mise tools by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1586](#1586)
- update dependency @types/node to v26 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1587](#1587)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1588](#1588)
- update mise tools to latest by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1592](#1592)
- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1593](#1593)
- update dependency effect to v4.0.6 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#1596](#1596)
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.

Cobra exporter emits invalid Usage defaults for true and negative integers

1 participant