cmd: add generic command builder (PRINFRA-121) - #10
Merged
somanshreddy merged 1 commit intoMar 31, 2026
Merged
Conversation
This was referenced Mar 31, 2026
Collaborator
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Mar 31, 2026
PRINFRA-121 CLI M1: OpenAPI codegen pipeline
Build the code generation pipeline that reads Scope
Mapping Rules
Acceptance Criteria
|
somanshreddy
force-pushed
the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
from
March 31, 2026 21:06
038909b to
1c8298f
Compare
somanshreddy
force-pushed
the
03-31-client_refactor_executor_to_use_command.spec_command.invocation
branch
from
March 31, 2026 21:06
691cf11 to
8116acf
Compare
somanshreddy
force-pushed
the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
from
March 31, 2026 21:25
1c8298f to
d9d1b26
Compare
somanshreddy
force-pushed
the
03-31-client_refactor_executor_to_use_command.spec_command.invocation
branch
2 times, most recently
from
March 31, 2026 21:55
6d230d5 to
6dd7748
Compare
somanshreddy
force-pushed
the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
from
March 31, 2026 21:55
d9d1b26 to
6cdb863
Compare
somanshreddy
marked this pull request as ready for review
March 31, 2026 22:01
somanshreddy
force-pushed
the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
from
March 31, 2026 22:02
6cdb863 to
8ff960a
Compare
jrusso1020
reviewed
Mar 31, 2026
jrusso1020
approved these changes
Mar 31, 2026
jrusso1020
reviewed
Mar 31, 2026
somanshreddy
force-pushed
the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
from
March 31, 2026 22:34
8ff960a to
836b5d0
Compare
Collaborator
Author
Merge activity
|
somanshreddy
changed the base branch from
03-31-client_refactor_executor_to_use_command.spec_command.invocation
to
graphite-base/10
March 31, 2026 22:39
buildGenCommand converts a command.Spec into a Cobra command: registers typed flags, adds --json-body for JSON body endpoints, validates enums and min/max, builds Invocation from parsed flags/args. Also adds newRootCmdWithSpecs for testing spec-based command registration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
somanshreddy
force-pushed
the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
from
March 31, 2026 22:42
836b5d0 to
d9adbc8
Compare
somanshreddy
deleted the
03-31-cmd_add_generic_command_builder_for_generated_specs
branch
March 31, 2026 22:44
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.

Description
Adds the generic command builder — the bridge between generated Specs (pure data) and the Cobra command tree.
The problem: Codegen produces
command.Specstructs — endpoint, method, flags, args. Cobra needs*cobra.Commandobjects with RunE functions, registered flags, and arg validators. Something needs to convert one to the other. That's whatbuildCobraCommanddoes.What it does for every generated command:
--limitbecomesIntVar,--titlebecomesStringVar,--draftbecomesBoolVar,--eventsbecomesStringSliceVar. Defaults, required flags, and enum help text all handled automatically.-d/--dataflag for commands withBodyEncoding: "json"— the escape hatch for complex request bodies (discriminated unions, nested objects). Accepts inline JSON, a file path, or-for stdin. Named to match curl and Stripe CLI conventions.cobra.ExactArgs(len(spec.Args))ensures the right number of positional args-dinput if provided (inline JSON, file, or stdin viareadData)spec.BuildInvocation()to resolve flags + args into an Invocation (with merge order:-dbase → positional args → flags overlay)client.Execute(spec, inv)to send the HTTP requestformatter.Data(result)to write JSON to stdoutWhy this matters: This is what makes "generated commands are data, not logic" work. All 40 generated commands go through this same function. No per-command code. Add a new endpoint to the OpenAPI spec, run
make generate, and it works — because the builder handles everything generically.Also in this PR:
newRootCmdWithSpecs— a test helper that builds a full Cobra tree from Specs instead of hand-written commands. This enables integration tests that prove the builder produces identical behavior to the M0 hand-written video list command.Testing
6 integration tests using httptest mocks:
Files
cmd/heygen/builder.go—buildCobraCommand,registerFlag,readData,buildUseLinecmd/heygen/builder_test.go— 6 integration tests with httptestcmd/heygen/root.go— addednewRootCmdWithSpecsfor test support