fix(cli): strip launch-global flags before non-launch subcommands
`resolveCliArgv` hoisted a subcommand hidden behind leading global launch flags to the front and forwarded those flags to the subcommand's own parser (#2970). Launch-shaped commands (`launch`/`acp`) share the launch flag surface, but strict-parsing subcommands like `update` declare only their own flags, so a leading `--cwd` reached `node:util.parseArgs` and threw `Unknown option '--cwd'`. This bit users whose shell alias/wrapper runs `omp --cwd <dir> update`. Leading launch-global flags are now stripped when the hoisted subcommand is not launch-shaped, and still forwarded for `launch`/`acp`. Shared the launch-command set with the profile bootstrap to keep one source of truth. Fixes #8891
This commit is contained in:
@@ -62,3 +62,33 @@ describe("resolveCliArgv routes subcommands hidden behind leading global flags",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveCliArgv strips launch-global flags before non-launch subcommands (#8891)", () => {
|
||||
test("`--cwd <dir> update` drops the inapplicable launch flag instead of forwarding it", () => {
|
||||
// Forwarding `--cwd` into update's strict parser crashed with
|
||||
// `Unknown option '--cwd'`; the launch-only flag is now dropped.
|
||||
expect(resolveCliArgv(["--cwd", "/tmp", "update"])).toEqual({ argv: ["update"] });
|
||||
});
|
||||
|
||||
test("`--cwd=<dir>` inline form is stripped too", () => {
|
||||
expect(resolveCliArgv(["--cwd=/tmp", "update"])).toEqual({ argv: ["update"] });
|
||||
});
|
||||
|
||||
test("a trailing subcommand flag survives while the leading launch flag is stripped", () => {
|
||||
expect(resolveCliArgv(["--cwd", "/tmp", "update", "--force"])).toEqual({
|
||||
argv: ["update", "--force"],
|
||||
});
|
||||
});
|
||||
|
||||
test("multiple leading launch flags are all stripped before a non-launch subcommand", () => {
|
||||
expect(resolveCliArgv(["--model", "gpt", "--cwd", "/x", "update"])).toEqual({ argv: ["update"] });
|
||||
});
|
||||
|
||||
test("a subcommand's own flag placed before it is kept, not treated as launch-global", () => {
|
||||
expect(resolveCliArgv(["-c", "update"])).toEqual({ argv: ["update", "-c"] });
|
||||
});
|
||||
|
||||
test("launch-shaped `acp` still receives forwarded launch-global flags", () => {
|
||||
expect(resolveCliArgv(["--cwd", "/x", "acp"])).toEqual({ argv: ["acp", "--cwd", "/x"] });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user