[WIP] Add --generate-skeleton flag#5407
Draft
janniklasrose wants to merge 10 commits into
Draft
Conversation
Collaborator
Integration test reportCommit: 1fbdbe5
9 interesting tests: 4 SKIP, 3 RECOVERED, 2 flaky
Top 10 slowest tests (at least 2 minutes):
|
Remove the two demo wirings of RegisterGenerateSkeleton (jobs create and vector-search-endpoints create-endpoint). These were per-command overrides added while the command scaffolding was still generated in the universe repo, where the flag could not be added generically from the CLI repo. Now that codegen is driven by the in-repo internal/cligen generator and its templates, the flag will be emitted for every --json command from the template instead. RegisterGenerateSkeleton is intentionally left unreferenced here; the template wiring and regeneration in the following commits restore its call sites. Co-authored-by: Isaac
Define a reusable template block that emits a RegisterGenerateSkeleton call for a --json command. The skeleton target mirrors the --json unmarshal target (&req, or &req.<RequestBodyField> when the body is a nested field), so the printed skeleton always matches what --json accepts. The block is defined but not yet invoked, so regeneration produces no output change; the following commit wires the call. Co-authored-by: Isaac
Invoke the "generate-skeleton" template block from new<Method>(), guarded by $canUseJson so it only fires for commands that accept a --json request body. $canUseJson is declared at the top of the method body and implies a non-legacy-empty request, so the <method>Req variable the block references is always in scope. The call is emitted after the override loop so it wraps any RunE a manual override installed; --generate-skeleton then short-circuits the whole command. This is a template-only change; the generated stubs are regenerated in the next commit. Co-authored-by: Isaac
Run ./task generate-cligen after wiring the template. Every generated command that accepts a --json request body now registers --generate-skeleton. Purely additive: 482 commands across cmd/workspace/** and cmd/account/**, no manual edits. Co-authored-by: Isaac
Add coverage at three levels: - cmd/root/skeleton_test.go: unit tests for jsonSkeleton (primitives, pointers, slices, maps, time.Time, JSON-tag handling, recursion termination) and for RegisterGenerateSkeleton wiring (offline skeleton print, positional-arg relaxation, --json rejection, normal path preserved). - internal/cligen/skeleton_test.go: render service.go.tmpl and assert the emitted RegisterGenerateSkeleton target matches the --json unmarshal target (plain request vs request-body field), and that non-JSON commands get no flag. - acceptance/cmd/workspace/generate-skeleton: end-to-end output for a plain request, a request-body-field command with relaxed positional args, and the --json incompatibility error. Offline, so it opts out of the engine matrix. Also modernize skeleton.go for the linters that tightened after this branch forked (errors.New, reflect.TypeFor, reflect.Type.Fields iterator); behavior is unchanged. Co-authored-by: Isaac
Replace the single --generate-skeleton flag with two mutually exclusive flags: - --generate-skeleton-full: every field of the --json request body. - --generate-skeleton-required-only: only fields the API requires. Required-ness comes from the SDK struct tags: a field whose json tag lacks ",omitempty" is required. This is the SDK's own required-field convention and, unlike cli.json (which carries required only for the top-level request and one level into a request-body field), it holds recursively at every nesting level, so required-only prunes deep optional subtrees correctly. Keys stay sorted by name in both variants (json.MarshalIndent sorts map keys), so the two skeletons differ only in which fields are present, not their order. Mutual exclusion of the two flags is enforced by cobra (MarkFlagsMutuallyExclusive); combining either with --json is rejected with an actionable error naming the offending flag. The generated command stubs are unchanged: they still emit a single RegisterGenerateSkeleton call, and the two flags are registered inside it. Co-authored-by: Isaac
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.
Changes
Why
Tests
collapse review tree to hide auto-generated files: