fix(cli): name projection flags only where the command declares them - #187
Open
ysyneu wants to merge 2 commits into
Open
fix(cli): name projection flags only where the command declares them#187ysyneu wants to merge 2 commits into
ysyneu wants to merge 2 commits into
Conversation
A reduced structured list announces the reduction on stderr with advice to narrow --fields or lower --limit, but those flags are registered per verb, not globally. The note was composed inside the byte-bounding helper, which knows bytes and nothing about the running command, so a generated verb that declares neither flag (e.g. channel silence-rule-list, whose only flags are --channel-id and --data) was told to pass a flag it rejects (unknown flag: --limit), costing a round trip that cannot be obeyed. boundProjectedList now returns a projectionBound describing what it removed (rows kept/total, or values shortened and in which fields) instead of prose. noteProjectionBound composes the note against cmd's real flag set, naming only the flags the verb declares and saying plainly when it declares none. A --fields-only verb (channel escalate-rule-list) is no longer told to lower --limit, and a --limit-only verb (insight incident-list, monit rule-list-basic) is no longer told to narrow --fields. Tests cover a verb with --fields and --limit (incident list, alert-event list), one with --fields only, one with neither, and the --limit-only generated verbs, asserting the reduction is still announced with every emitted value intact.
The reduction note and the overflow error told the caller to narrow --fields or lower --limit whenever those flags existed, but a flag's name does not imply its effect: monit rule-update-fields spells a request-body write selector --fields, so obeying the advice would change a write instead of the output; safari knowledge-file-list documents its --limit as ignored; monit rule-list-basic honors its own only alongside --include-descendants. Commands now declare, in their own definition, the flags that narrow their structured output — a projection flag that shrinks each row, and a rows flag that requests fewer rows (declareOutputNarrowing, set next to the flag registrations). The hand-written projection verbs declare theirs; generated verbs declare none, because the spec has no structured contract for whether a --limit bounds the response, so their note names no flag at all. The byte-bounding helper composes no flag advice: it returns facts, and an irreducible overflow comes back as a flag-neutral error the caller completes (explainProjectionOverflow). The single-row shortening branch no longer offers a rows flag, since requesting fewer rows cannot shrink the one row that already overflows. Tests drive real verbs end to end: a write-selector --fields gets no --fields advice, an ignored or conditional --limit gets no --limit advice, the shortening note offers only the projection flag, and the overflow error names only flags the command declared.
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.
What
A reduced structured list announces the reduction on stderr, and that note used to advise
--fields/--limitunconditionally. Both flags are registered per verb, so a verb declaring neither was told to pass a flag it rejects (unknown flag: --limit) — and--fieldsis not always a projection control:monit rule-update-fieldsuses it to select which rule fields get written, so obeying the advice would change a write rather than the output.The byte-bounding helper no longer composes prose. It returns the facts about what it removed (
projectionBound), and the note is composed at the call site from the flags the command itself declares:declareOutputNarrowing, next to the flag registrations it names;declaredNarrowingdrops a declaration whose flag the command no longer carries, so a renamed flag degrades to no advice rather than naming a stale one;Generated verbs declare nothing deliberately: the OpenAPI spec carries no structured contract for whether a
--limitactually bounds the emitted rows (safari knowledge-file-listdocuments its limit as ignored;monit rule-list-basichonours it only with--include-descendants), so any generator rule would be inference. The decision is documented at the generator site so it cannot drift silently.Verification
make fmt,go build ./...,go vet ./...,go test -count=1 ./...— all green.execCommandSplit: declared projection+rows names both; projection-only never names--limit; the write-selector--fieldsgets no--fields; a no-declaration verb gets the flagless note; an ignored--limitis never offered; the shortening branch omits the rows flag; the overflow error path names only declared flags.