Skip to content

fix(cli): stop dropping repeated -p flags for required params - #438

Open
anttiviljami wants to merge 1 commit into
mainfrom
fix/cli-repeated-param-flag
Open

fix(cli): stop dropping repeated -p flags for required params#438
anttiviljami wants to merge 1 commit into
mainfrom
fix/cli-repeated-param-flag

Conversation

@anttiviljami

Copy link
Copy Markdown
Member

Summary

  • The CLI's -p key=value flag is defined as a plain type: 'string' citty arg. Citty parses args via node:util.parseArgs, which never sets multiple: true for any arg type (citty has no array/repeatable-string arg kind at all). With strict: false, a repeated string flag silently keeps only the last occurrence — no error, no warning.
  • So epilot entity getEntity -p slug=contact -p id=abc-123 only kept id=abc-123; slug was silently dropped before it ever reached collectParams/getMissingRequired, which then correctly reported slug as 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.
  • Added collectRepeatedFlag() (packages/cli/src/lib/flag-collector.ts) which recovers every -p/--param occurrence directly from rawArgs, bypassing citty's lossy parsing. Wired it into the generated per-API command template in scripts/generate.ts, then regenerated all src/commands/apis/*.ts files (mechanical, template-only diff — no unrelated OpenAPI spec drift included).
  • param-collector.ts/call.ts needed no changes — they already handled param as an array correctly; the value was just lost before reaching them.

Test plan

  • New unit tests for collectRepeatedFlag covering short/long flags, =-form, interleaved positionals/flags, -- separator, and prefix-collision edge cases (test/flag-collector.test.ts)
  • New regression test exercising the generated entity command's run() directly with rawArgs simulating citty's lossy args.param, asserting both -p values are forwarded to callApi (test/entity-command.test.ts)
  • pnpm test — 114/114 passing
  • pnpm lint — clean
  • pnpm typecheck — no new errors (pre-existing unrelated errors in call.ts/profiles.ts/bin/epilot.ts confirmed present on main before this change too)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant