CLI: add fuzzy selector when no command is given

This commit is contained in:
Benjamin Jesuiter
2026-02-16 20:18:48 +01:00
parent 32d12fcae9
commit 3e9e9258a4
4 changed files with 335 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import {
shouldEnsureCliPath,
shouldRegisterPrimarySubcommand,
shouldSkipPluginCommandRegistration,
shouldUseInteractiveCommandSelector,
} from "./run-main.js";
describe("rewriteUpdateFlagArgv", () => {
@@ -103,6 +104,64 @@ describe("shouldSkipPluginCommandRegistration", () => {
});
});
describe("shouldUseInteractiveCommandSelector", () => {
it("enables selector for plain no-arg interactive invocations", () => {
expect(
shouldUseInteractiveCommandSelector({
argv: ["node", "openclaw"],
stdinIsTTY: true,
stdoutIsTTY: true,
}),
).toBe(true);
});
it("disables selector when a command is already present", () => {
expect(
shouldUseInteractiveCommandSelector({
argv: ["node", "openclaw", "status"],
stdinIsTTY: true,
stdoutIsTTY: true,
}),
).toBe(false);
});
it("disables selector for non-interactive terminals or CI", () => {
expect(
shouldUseInteractiveCommandSelector({
argv: ["node", "openclaw"],
stdinIsTTY: false,
stdoutIsTTY: true,
}),
).toBe(false);
expect(
shouldUseInteractiveCommandSelector({
argv: ["node", "openclaw"],
stdinIsTTY: true,
stdoutIsTTY: true,
ciEnv: "1",
}),
).toBe(false);
expect(
shouldUseInteractiveCommandSelector({
argv: ["node", "openclaw"],
stdinIsTTY: true,
stdoutIsTTY: true,
disableSelectorEnv: "1",
}),
).toBe(false);
});
it("disables selector for help/version invocations", () => {
expect(
shouldUseInteractiveCommandSelector({
argv: ["node", "openclaw", "--help"],
stdinIsTTY: true,
stdoutIsTTY: true,
}),
).toBe(false);
});
});
describe("shouldEnsureCliPath", () => {
it("skips path bootstrap for help/version invocations", () => {
expect(shouldEnsureCliPath(["node", "openclaw", "--help"])).toBe(false);