Skip to content

feat(cli): suggest the vp run order when package flags come first - #3500

Merged
fengmk2 merged 14 commits into
voidzero-dev:mainfrom
naokihaba:feat/suggest-run-flag-order
Nov 21, 2026
Merged

fengmk2 merged 14 commits into
voidzero-dev:mainfrom
naokihaba:feat/suggest-run-flag-order

Conversation

@naokihaba

@naokihaba naokihaba commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Right now, commands like vp --filter backend run dev fail with an UnknownArgument error because clap doesn't recognize the vite-task PackageQueryArgs flags (--filter, -r, -t, -w, and --fail-if-no-match) before run. Since pnpm supports this order, it's easy to type this by muscle memory and end up having to re-enter the whole line.

This PR fixes that by suggesting the command with those flags moved after run.

Command output

In an interactive terminal, the global CLI asks whether to run the corrected command. In this example, the backend package has a dev script that prints dev from backend.

$ vp --filter backend run dev
VITE+ - The Unified Toolchain for the Web

error: Unexpected argument '--filter'

Do you want to run `vp run --filter backend dev`? (y/N): y
$ echo dev from backend ⊘ cache disabled
dev from backend

Press Enter or type n to skip the task and exit with code 2.

In CI or when stdin or stderr is redirected, the global CLI prints the correction and exits with code 2. The project-local CLI also prints this hint and exits with code 2.

error: Unexpected argument '--filter'

Did you mean `vp run --filter backend dev`?

Both binaries wrap values in quotes so arguments parse properly across POSIX shells, Command Prompt, and PowerShell (for instance, keeping quotes in --filter "@my/*"). However, if an argument has characters like !, $, or % that certain shells expand even inside double quotes, we skip the suggestion entirely to be safe.

If you passed a -C flag, the suggestion will prepend -C "<absolute path>" so you can paste and run it from anywhere and still hit the right workspace.

Note that this only covers vp run and the specific PackageQueryArgs flags mentioned above. We don't suggest fixes for unrecognized flags or combined short flags like -rw.

Snapshot cases wait for a milestone before they send keystrokes. The
y/N prompt that offers a corrected command had no milestone, so a
snapshot could not answer it.
move_flags_after_command takes the clap options that a command accepts.
It moves those options from before the command name to after it, for
example `--filter app run dev` to `run --filter app dev`. It returns
None when an argument before the command is not one of those options,
or when the command does not follow them.
`vp --filter backend run dev` fails at the top level, because only
`vp run` accepts these flags. pnpm accepts them in that order, so users
often type it.

The global CLI now asks to run `vp run --filter backend dev`, as it does
for a top-level typo. The local CLI has no prompt, so it prints the order
with "Did you mean". Both CLIs pass vite-task's PackageQueryArgs to the
helper, so the accepted flags are the same as `vp run`.

Refs: voidzero-dev#2983
@naokihaba

Copy link
Copy Markdown
Collaborator Author

@codex review

@naokihaba naokihaba self-assigned this Nov 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T05:34:42.731223Z 55a4301 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d15531f91a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/binding/src/cli/help.rs Resolved
The suggested command joined the arguments with spaces, so a copied
suggestion did not give the original arguments. For example,
`--filter "@my/*"` became `--filter @my/*`, and zsh stops with
"no matches found". The suggestion now quotes each argument for a POSIX
shell with `shell_escape::unix::escape`.

The `y` answer in the global CLI still runs the argument vector
directly, so only the displayed text changes.
@naokihaba

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6073192c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/binding/src/cli/help.rs Resolved
Both CLIs apply `-C <dir>` and remove it from the arguments before
parsing. The suggestion for `vp -C ../other -r run build` was
`vp run -r build`, which runs in the wrong workspace when the user
copies it. When `-C` was used, the suggestion now starts with
`-C <absolute dir>`, so it selects the same workspace from any shell.
@naokihaba

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a672665dda

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vp_cli_help/src/error.rs Resolved
Command Prompt passes single quotes through, so the POSIX quoting turned
`--filter "@my/*"` into a filter that matches no package. On Windows, the
suggestion now puts a value in double quotes, which Command Prompt and
PowerShell both read as one argument.

In double quotes, Command Prompt expands `%NAME%` and PowerShell expands
`$name`, so no text gives both shells the same value. When a value has
`%`, `$`, a backtick, or a double quote, the CLIs show no suggestion.
The suggestion used shell-escape on POSIX and a separate rule on Windows.
It now uses one rule like `quoteArgument` in the migrator: a plain value
stays as it is, a value with only spaces, `@`, `*`, `,`, backslashes, or
letters goes in double quotes, and any other value gives no suggestion.
POSIX shells, Command Prompt, and PowerShell read the double-quoted text
as the same value.

`vp_cli_help` no longer depends on shell-escape.
@naokihaba

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 29f24046d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@naokihaba
naokihaba marked this pull request as ready for review November 20, 2026 18:10
@naokihaba
naokihaba requested review from fengmk2 and removed request for fengmk2 November 20, 2026 18:10
@naokihaba
naokihaba marked this pull request as draft November 20, 2026 18:10
@naokihaba
naokihaba marked this pull request as ready for review November 20, 2026 18:21
@naokihaba
naokihaba requested a review from fengmk2 November 20, 2026 18:21
Comment thread crates/vp_global_cli/src/main.rs Resolved
Comment thread crates/vp_cli_help/src/error.rs Resolved
Comment thread crates/vp_global_cli/src/main.rs Resolved
@naokihaba
naokihaba marked this pull request as draft November 21, 2026 04:43
Some CI systems run commands in a pseudo-terminal, so the TTY checks pass
and `vp --filter backend run dev` waits at `(y/N)` until the job times out.
Check `is_ci_environment()` before the prompt, and record a PTY step with
`CI=1`.
The scan counts option lengths only, so it suggested commands that fail:
`vp --filter -r run build` takes `-r` as the filter value, which clap
rejects, and `vp -r --filter backend run build` combines options that
vite-task rejects. Parse the moved options with clap, and let callers
check them with `PackageQueryArgs::into_package_query`, so that
`vp_cli_help` stays independent of vite-task.
Without a terminal or in CI, the global CLI printed only the argument
error, while the local CLI also printed the corrected command. Print
"Did you mean `vp run ...`?" in both CLIs and exit with code 2, without a
prompt and without running the task, so that a CI log shows the fix.
@naokihaba

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 55a4301ec7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@naokihaba
naokihaba requested a review from fengmk2 November 21, 2026 05:35
@naokihaba
naokihaba marked this pull request as ready for review November 21, 2026 05:35
@fengmk2
fengmk2 merged commit e98aaa0 into voidzero-dev:main Nov 21, 2026
78 checks passed
@fengmk2 fengmk2 mentioned this pull request Nov 23, 2026
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.

Accept arguments before command name (e.g. vp -r run)

2 participants