Skip to content

Show each API flag's type in help, not a word from its description - #39

Open
edumansky wants to merge 2 commits into
mainfrom
cli-flag-placeholders
Open

edumansky wants to merge 2 commits into
mainfrom
cli-flag-placeholders

Conversation

@edumansky

@edumansky edumansky commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Why

pflag treats the first `word` in a flag's usage as the name of the value the flag takes. It shows that word after the flag and removes those backticks. Cisco's parameter descriptions use backticks for code, so 615 generated flags showed a word from their description where the value type should be. Later backticks stayed in the text. From webex cc activities get-input-choices --help:

--input-name allowedValues        Input field name. ... (has allowedValues or a `choicesEndpoint`).
--parent-value channelType        Parent input value ... (for example, the selected channelType).
--search validate=true            Search text ... When validate=true, this is instead the single value to look up.

--search takes a string, but its help reads as if it takes validate=true.

What changes

internal/apicmd removes backticks from a parameter's description when it registers the flag. Every generated flag now shows its type:

--input-name string          Input field name. ... (has allowedValues or a choicesEndpoint).
--parent-value string        Parent input value ... (for example, the selected channelType).
--search string              Search text ... When validate=true, this is instead the single value to look up.

pkg/webexops still has Cisco's descriptions unchanged, so the skill references and SDK users still get the Markdown.

Golden files

In testdata/golden/commands.json, the only changed lines are 615 flag usage lines, which lost their backticks. The recorded requests are unchanged. The golden file doesn't record the value name, so TestAFlagWithCodeInItsUsageShowsItsType checks it.

Checks

  • go vet ./... and go test -p 1 -timeout 300s ./... pass.
  • gofmt reports no files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JAtGHcFAKjQdB6dwDKd8mW


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

edumansky and others added 2 commits November 18, 2026 15:30
pflag takes the first backticked word in a flag's usage as the value name,
so Cisco's Markdown code spans showed as `--search validate=true` and
`--input-name allowedValues`. Backticks are now dropped from usage when the
flag is registered; pkg/webexops keeps Cisco's descriptions as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAtGHcFAKjQdB6dwDKd8mW
Building a strings.Replacer per parameter added about 35 MB of allocations
to every CLI start, since every API command's flags are registered then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAtGHcFAKjQdB6dwDKd8mW

@edumansky edumansky left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review (gpt-6.2-astra, reasoning effort: high)

The flag placeholders are corrected, and the focused regression test and golden tests pass. The implementation nevertheless adds roughly 35 MB of avoidable allocations to every CLI invocation.

Comment thread internal/apicmd/apicmd.go Outdated
// the first `word` in a usage as the flag's value name, and Cisco's descriptions
// use backticks only to mark code, so they are dropped.
func flagUsage(description string) string {
return strings.NewReplacer("\n", " ", "`", "").Replace(description)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Reuse the flag-help replacer across parameters

flagUsage builds the same replacement table for every parameter. All six command areas use this builder at startup, even for webex --version. With GODEBUG=inittrace=1, those areas allocated about 43 MB during initialization versus 8 MB on the base branch. Construct the strings.Replacer once at package scope and reuse it to preserve the corrected help without the extra startup allocations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 9640f7f. The replacer is now built once at package scope (usageReplacer). Measured with GODEBUG=inittrace=1 webex --version: 42.8 MB in cmd/ inits before, 8.6 MB after (8.3 MB on main). Regression test: TestFlagUsageAllocatesOnlyItsResult checks that flagUsage makes at most one allocation.

@edumansky

Copy link
Copy Markdown
Contributor Author

Codex review: outcome

Codex's one finding was valid and is fixed in 9640f7f:

Finding Outcome
[P2] Reuse the flag-help replacer across parameters Fixed: the strings.Replacer is built once at package scope. Startup allocations in cmd/ inits measured with GODEBUG=inittrace=1 webex --version: 42.8 MB before the fix, 8.6 MB after, against 8.3 MB on main. Test: TestFlagUsageAllocatesOnlyItsResult

Checks at 9640f7f:

  • go vet ./... and go test -p 1 -timeout 300s ./... pass, golden tests included; gofmt reports no files.

This branch has not been deployed

No deployments
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.

1 participant