Skip to content

Replace argv-hoist preprocessor with a Stricli "top-level flags" patch #1339

Description

@jared-outpost

Follow-up from #1337 (discussion with @BYK).

Background

#1337 makes --help --json emit structured output by rewriting the argv into a help command invocation inside preprocessArgv (src/lib/argv-hoist.ts). That landed as the interim fix, but the whole argv-hoist.ts preprocessor exists only because Stricli parses flags at the leaf level and treats global flags placed before the subcommand as unknown route segments. We work around that today by hoisting --verbose, --log-level, --json, --fields, --org, --project to the tail, normalizing --version, and rewriting --help --json.

Proposal

Teach Stricli about a configurable set of top-level flags (via our @stricli/core patch, same mechanism as the existing -H removal) so those flags are recognized at any route depth and handed to the leaf command. This removes the need for argv-hoist.ts entirely — no hoisting, no --version normalization, no --help --json rewrite.

buildRouteScanner is the natural hook: it already special-cases --help/--helpAll/--version while walking the route tree, so it can collect an allow-list of global flags instead of failing route resolution on them.

Design note (from @BYK)

"Terminal" flags like --help should not short-circuit. They should still parse the other flags on the line and pass them to their handler, which may ignore them or act on them. That is what lets --help --json produce JSON: --help stays terminal for routing, but --json reaches the handler and switches output to our introspectCommand/introspectAllCommands structured form. So the scanner change needs a small amount of app-level glue to route "help + json" to structured output rather than text usage.

Tasks

  • Extend the @stricli/core patch with a top-level-flags allow-list in buildRouteScanner.
  • Make terminal flags (--help) still parse sibling flags and forward them to the handler.
  • Wire the app so --help --json renders structured help via existing introspection.
  • Delete src/lib/argv-hoist.ts and its preprocessArgv usage once the patch covers all cases; migrate/prune the associated tests.
  • Submit the top-level-flags behavior (and the existing -H change) as PRs upstream to Stricli; keep the local patch until/unless accepted.

Notes

  • The patch targets minified dist/index.{cjs,js}; check-patches.ts already flags that every Stricli bump requires re-deriving it, so keep the edit minimal.
  • Closing criterion: argv-hoist.ts is gone and all existing argv-hoist / help-json / version behaviors are covered by the patched scanner plus app glue, with equivalent test coverage.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestjaredTrigger the Jared agent to work on stuff

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions