fix(cli): preserve lazy command parent flags

This commit is contained in:
Peter Steinberger
2026-04-30 00:48:46 +01:00
parent 36bb723dfb
commit 01254500df
7 changed files with 186 additions and 29 deletions

View File

@@ -1,6 +1,11 @@
import { Command } from "commander";
import { describe, expect, it } from "vitest";
import { collectOption, parsePositiveIntOrUndefined, resolveActionArgs } from "./helpers.js";
import {
collectOption,
parsePositiveIntOrUndefined,
resolveActionArgs,
resolveCommandOptionArgs,
} from "./helpers.js";
describe("program helpers", () => {
it("collectOption appends values in order", () => {
@@ -38,4 +43,46 @@ describe("program helpers", () => {
expect(resolveActionArgs(command)).toEqual([]);
expect(resolveActionArgs(undefined)).toEqual([]);
});
it("resolveCommandOptionArgs serializes explicit options", () => {
const command = new Command()
.option("--json", "JSON output", false)
.option("--timeout <ms>", "Timeout", "30000")
.option("--tag <name>", "Tag", collectOption)
.option("--no-progress", "Disable progress");
command.parse([
"node",
"test",
"--json",
"--timeout",
"10",
"--tag",
"a",
"--tag",
"b",
"--no-progress",
]);
expect(resolveCommandOptionArgs(command)).toEqual([
"--json",
"--timeout",
"10",
"--tag",
"a",
"--tag",
"b",
"--no-progress",
]);
});
it("resolveCommandOptionArgs skips defaults", () => {
const command = new Command()
.option("--json", "JSON output", false)
.option("--timeout <ms>", "Timeout", "30000");
command.parse(["node", "test"]);
expect(resolveCommandOptionArgs(command)).toEqual([]);
});
});