fix(cli): stop dropping repeated -p flags for required params - #438
Open
anttiviljami wants to merge 1 commit into
Open
fix(cli): stop dropping repeated -p flags for required params#438anttiviljami wants to merge 1 commit into
anttiviljami wants to merge 1 commit into
Conversation
citty parses args via node:util.parseArgs, which never enables "multiple" for any arg type, so a repeated string flag (e.g. -p a=1 -p b=2) silently keeps only the last occurrence in args.param -- earlier -p flags vanish with no error. Any operation needing more than one -p (the common case for required path/query params) would then have those earlier params reported as missing and get re-prompted interactively, even though they were passed on the command line. Add collectRepeatedFlag() to recover every -p/--param occurrence directly from rawArgs, and wire it into the generated per-API command template (scripts/generate.ts) so it takes precedence over cittys lossy args.param whenever more than one occurrence is present. Co-Authored-By: Claude Sonnet 5 <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
-p key=valueflag is defined as a plaintype: 'string'citty arg. Citty parses args vianode:util.parseArgs, which never setsmultiple: truefor any arg type (citty has no array/repeatable-string arg kind at all). Withstrict: false, a repeated string flag silently keeps only the last occurrence — no error, no warning.epilot entity getEntity -p slug=contact -p id=abc-123only keptid=abc-123;slugwas silently dropped before it ever reachedcollectParams/getMissingRequired, which then correctly reportedslugas missing and re-prompted for it interactively — even though the user passed it on the command line. This is exactly the "not read at all, or asked twice" behavior reported.collectRepeatedFlag()(packages/cli/src/lib/flag-collector.ts) which recovers every-p/--paramoccurrence directly fromrawArgs, bypassing citty's lossy parsing. Wired it into the generated per-API command template inscripts/generate.ts, then regenerated allsrc/commands/apis/*.tsfiles (mechanical, template-only diff — no unrelated OpenAPI spec drift included).param-collector.ts/call.tsneeded no changes — they already handledparamas an array correctly; the value was just lost before reaching them.Test plan
collectRepeatedFlagcovering short/long flags,=-form, interleaved positionals/flags,--separator, and prefix-collision edge cases (test/flag-collector.test.ts)entitycommand'srun()directly with rawArgs simulating citty's lossyargs.param, asserting both-pvalues are forwarded tocallApi(test/entity-command.test.ts)pnpm test— 114/114 passingpnpm lint— cleanpnpm typecheck— no new errors (pre-existing unrelated errors incall.ts/profiles.ts/bin/epilot.tsconfirmed present onmainbefore this change too)🤖 Generated with Claude Code