You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cobra exporter emits invalid Usage defaults for true and negative integers #1594
The Cobra integration emits some flag defaults as bare KDL values, but Usage expects string defaults. Reproduced with the adapter pinned to Usage v7.1.3 (f357a6c096be219a3166346dbb199ab36d5be73a, Go module pseudo-version v0.0.0-20261026100501-f357a6c096be) and usage 7.1.3.
Minimal example:
package main
import (
"fmt"
cobrausage "github.com/jdx/usage/integrations/cobra""github.com/spf13/cobra"
)
funcmain() {
cmd:=&cobra.Command{Use: "example"}
cmd.Flags().Bool("enabled", true, "Enable the feature")
// Test independently too:// cmd.Flags().Int("parallel", -1, "Maximum parallelism")fmt.Print(cobrausage.Generate(cmd))
}
For the boolean, the output includes:
flag--enabledhelp="Enable the feature"default=true
Passing the generated document to usage lint fails with “Expected identifier string”. When the boolean flag is replaced with the commented integer flag, the output is:
That fails with “Invalid usage config” / “expected string”.
Expected defaults: default="true" and default="-1".
In needsQuoting at the pinned commit, leading digits and some punctuation trigger quoting, but reserved words and signed numeric strings do not. Quoting all serialized string defaults, or extending that check, would avoid the problem. A round trip through Usage's parser would cover both cases.
AI-assisted report; both examples were run against the pinned adapter and CLI.
Activity
github-actions commentedon Oct 30, 2026
Fixed in v7.1.4 by #1595.