Register a product namespace as a Cobra command, and retire the second flag parser
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 0
- Forks
- 3
- Avg merge
- 8h 43m
- Merged PRs (30d)
- 60
Description
Follow-up to #86 and #85. Two of #86's user stories were not delivered by PR #150, and both wait on the same change.
What is left
US13: one parser for the output flag. "the duplicated interpretation of the output flag removed, so that there is one parser for it." internal/app/productargs.go still reads --output, -o, and --context by hand for a product line, beside the pflag parser the root command uses for every built-in. internal/app/outputflag_internal_test.go exists only to pin the two against each other, and its own doc comment says the duplication ends when each command declares its flags.
US14: suggestions across shell and product commands. internal/app/command.go still sets DisableSuggestions: true. #150 added suggestions inside a resolved namespace, so a mistyped product command is now named, but Cobra's own suggestions are still off and product namespaces are not among what it would suggest.
Shell completion. ADR 0008 says completion should not ship until modules declare their trees, because one that knows every built-in and no product command reads as "that command does not exist". Modules declare their trees now, but Cobra's __complete walks the Cobra tree and product namespaces bypass Cobra entirely at internal/app/app.go:152, so completion still cannot see them.
The one change underneath all three
A product namespace is not a Cobra command. app.go forks on strings.HasPrefix(name, "-") || isShellCommand(...) and dispatches a namespace outside Cobra, which is why the shell parses a product line itself, cannot suggest across the boundary, and cannot complete past it.
ADR 0008 considered registering each resolved namespace as a Cobra command and deferred it rather than rejecting it, on the grounds that without a declared command tree it bought suggestions at the price of a module store read on every invocation. The declaration now exists, and is local, verified, and already read before parsing — so the reason for the deferral is gone. That ADR is the place to record the reversal.
Sequence this behind #147
#147's first finding is the same surface: --context and --output moving off the root's persistent flags so that help stops advertising flags a command refuses. Both changes rewrite internal/app/command.go's flag declaration and the namespace dispatch. Whichever lands second pays for the conflict, and #147 is further along.
Note
#150 left internal/app/productargs.go deliberately, for exactly this reason. Its shellFlags.read is the second parser US13 removes; the fallback path for a module that declares no tree still needs hand parsing, so removing the duplication means deciding what that fallback becomes rather than deleting it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ADR 0008 and the namespace dispatch in internal/app/app.go, then inspect flag declarations and suggestion handling in internal/app/command.go and the fallback parser in internal/app/productargs.go. Check #147 before changing the shared surface. Done means product namespaces are visible to Cobra for suggestions and completion, output parsing is no longer duplicated, and the fallback behavior is explicitly resolved and tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100