feat: Add OpenCLIDescriber interface to expose a command's OpenCLI metadata#58
Merged
Conversation
…metadata Commands discovered via the OpenCLI contract now retain their node-local OpenCLI metadata (arguments, options, description, examples, exit codes, hidden, interactive, ...) captured from `--help-opencli`. The new optional `OpenCLIDescriber` interface surfaces it, mirroring the `ContractReporter` pattern: consumers type-assert a discovered Command and call `OpenCLICommand()`. `OpenCLICommand()` returns nil for commands discovered via other contracts. The returned Command describes only its own node; its Commands field is not populated, so callers walk Subcommands() to describe the tree. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Commands discovered via the
OpenCLIContractparse a rich--help-openclidocument (arguments, options, descriptions, examples, exit codes, hidden/interactive flags, ...), but until now that metadata was discarded — theCommandinterface only exposed name/summary/aliases/defaultCommand/subcommands. Consumers (e.g. thesqentrypoint) could therefore only reproduce a stripped-down OpenCLI document for commands they discover.This adds an optional companion interface,
OpenCLIDescriber, that surfaces each node's OpenCLI metadata, following the same pattern asContractReporter(#57): theCommandinterface is unchanged, and consumers type-assert a discovered command to reach the richer data.Details
commandDescriptorgains an unexportedopenCLI *opencli.Commandfield, populated byopencliToDescriptorfor every node in the tree. ItsCommandsfield is stripped — children remain reachable viaSubcommands(), keeping a single source of truth for the tree.executableCommandthreads that metadata throughdiscover()/toCommands()and implementsOpenCLICommand(). It returnsnil(not a synthesized fallback) for commands discovered via any other contract.OpenCLICommand()returns a copy describing only the node; itsCommandsfield is not populated.Commandinterface. Built-in commands do not implementOpenCLIDescriber.Test plan
go test ./...gofmt -l ./goimports -l ./go vet ./...cleanTestOpenCLICommandExposesMetadata(root + hidden subcommand carrying options/arguments/hidden),TestOpenCLICommandForNonOpenCLIContract(returns nil)sqentrypoint:sq <cmd> --help-openclinow reproduces the full OpenCLI document emitted by the underlying binary