fix(cli): consume global flags placed before the namespace tool#86
Open
chiplay wants to merge 1 commit into
Open
fix(cli): consume global flags placed before the namespace tool#86chiplay wants to merge 1 commit into
chiplay wants to merge 1 commit into
Conversation
With DisableFlagParsing on the namespace commands, cobra passes any
global flag that appears before the tool subcommand (e.g. "subtext
--format=text live view-list") straight through to namespaceRunE as
args[0]. The dispatcher then glued it onto the tool name
("live---format=text"), which 404s. extractGlobalFlags only ran later
in runCall, too late to rescue the tool name.
Run extractGlobalFlags at the top of namespaceRunE so leading globals
(--format/--api-key/--region/--endpoint/--config) are consumed before
the tool name is derived. runCall still calls it on the remainder, now
a no-op for globals.
Add a regression test for a leading --format=text and verify against
the production endpoint that both "--format=text doc list" and the
space-separated form resolve correctly.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Global flags placed before the namespace name break (P2 papercut, separate from #85's P0):
Affects all globals (
--format/--api-key/--region/--endpoint/--config) in the pre-namespace position.Root cause
The namespace commands use
DisableFlagParsing, so cobra hands any leading global flag through tonamespaceRunEasargs[0]. The dispatcher doestoolName := cmd.Use + "-" + args[0], gluing the flag onto the tool name (doc---format=text).extractGlobalFlagsonly ran later insiderunCall— after the bad tool name was already built and dispatched.Fix
Run
extractGlobalFlagsat the top ofnamespaceRunE, before deriving the tool name, so leading globals are consumed first.runCallstill calls it on the remainder (a no-op once globals are gone).Test + verification
TestNamespaceDispatchGlobalFlagBeforeTool— asserts a leading--format=textis consumed as a global (not glued) and the tool resolves.go test ./...clean.subtext --format=text doc listand the space-separated--format textform both resolve correctly; flags-after still work.🤖 Generated with Claude Code
Note
Low Risk
Small CLI dispatch change with a targeted integration test; no auth, data, or server-side impact.
Overview
Namespace commands (
doc,live, etc.) now accept global flags before the tool subcommand (e.g.subtext --format=text doc list), matching the behavior users expect from normal cobra parsing.Because namespace parents use
DisableFlagParsing, leading globals were passed through as the first positional arg and concatenated into a bogus tool name (doc---format=text).namespaceRunEnow runsextractGlobalFlagsfirst, so globals are stripped before the tool name is built;runCallstill parses any remaining globals afterward.An integration test asserts
tools/callsucceeds,--formatis applied, and output is rendered in text mode.Reviewed by Cursor Bugbot for commit d89d704. Bugbot is set up for automated code reviews on this repo. Configure here.