Support update command aliases and case-insensitive compatibility
This commit is contained in:
1 parent
31b7565a2d
commit
50f7a03903
2 files changed
+55
-6
No files matched your search
@@ -65,4 +65,37 @@ describe("CLI runner", () => {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("supports update aliases (upgrade, up) with notice in stderr and exit code 0", async () => {
|
||||
const upgradeResult = await runCli(["upgrade", "0.3.3"]);
|
||||
expect(upgradeResult.exitCode).toBe(0);
|
||||
expect(upgradeResult.isError).toBe(false);
|
||||
expect(upgradeResult.stderr).toContain("Notice: 'upgrade' is an alias for 'seal-use update'");
|
||||
expect(JSON.parse(upgradeResult.stdout)).toMatchObject({ updated: false, targetVersion: "0.3.3" });
|
||||
|
||||
const upResult = await runCli(["up", "0.3.3"]);
|
||||
expect(upResult.exitCode).toBe(0);
|
||||
expect(upResult.isError).toBe(false);
|
||||
expect(upResult.stderr).toContain("Notice: 'up' is an alias for 'seal-use update'");
|
||||
expect(JSON.parse(upResult.stdout)).toMatchObject({ updated: false, targetVersion: "0.3.3" });
|
||||
});
|
||||
|
||||
test("supports case-insensitive update invocations with original command in notice", async () => {
|
||||
const mixedResult = await runCli(["Update", "0.3.3"]);
|
||||
expect(mixedResult.exitCode).toBe(0);
|
||||
expect(mixedResult.stderr).toContain("Notice: 'Update' is an alias for 'seal-use update'");
|
||||
expect(JSON.parse(mixedResult.stdout)).toMatchObject({ updated: false, targetVersion: "0.3.3" });
|
||||
|
||||
const upperResult = await runCli(["UPGRADE", "0.3.3"]);
|
||||
expect(upperResult.exitCode).toBe(0);
|
||||
expect(upperResult.stderr).toContain("Notice: 'UPGRADE' is an alias for 'seal-use update'");
|
||||
expect(JSON.parse(upperResult.stdout)).toMatchObject({ updated: false, targetVersion: "0.3.3" });
|
||||
});
|
||||
|
||||
test("canonical update command does not emit alias notice", async () => {
|
||||
const result = await runCli(["update", "0.3.3"]);
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stderr).not.toContain("is an alias for 'seal-use update'");
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({ updated: false, targetVersion: "0.3.3" });
|
||||
});
|
||||
});
|
||||
+22
-6
@@ -59,6 +59,14 @@ import {
|
||||
import type { CliResult, CliRunOptions, CliRuntime } from "./types.js";
|
||||
|
||||
const DEFAULT_APP_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
||||
export const UPDATE_ALIASES = new Set([
|
||||
"update",
|
||||
"upgrade",
|
||||
"up",
|
||||
"self-update",
|
||||
"selfupdate"
|
||||
]);
|
||||
|
||||
export const KNOWN_AREAS = new Set([
|
||||
"config",
|
||||
"service",
|
||||
@@ -174,7 +182,10 @@ async function runCliOnce(argv: string[], options: CliRunOptions): Promise<CliRe
|
||||
|
||||
async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
const args = parseArgs(argv);
|
||||
const [area, action, maybeName] = args.command;
|
||||
const [rawArea, action, maybeName] = args.command;
|
||||
const lowerArea = rawArea?.toLowerCase();
|
||||
const isUpdate = lowerArea ? UPDATE_ALIASES.has(lowerArea) : false;
|
||||
const area = isUpdate ? "update" : lowerArea;
|
||||
|
||||
if (
|
||||
area === "version" ||
|
||||
@@ -263,16 +274,21 @@ async function dispatch(argv: string[], runtime: CliRuntime) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "update" || area === "changelog") {
|
||||
if (isUpdate || area === "changelog") {
|
||||
if (isUpdate && rawArea !== "update") {
|
||||
console.error(`⚠️ Notice: '${rawArea}' is an alias for 'seal-use update'. Please use 'seal-use update' instead.`);
|
||||
}
|
||||
|
||||
const lowerAction = action?.toLowerCase();
|
||||
const isChangelog =
|
||||
area === "changelog" ||
|
||||
action === "changelog" ||
|
||||
action === "log" ||
|
||||
action === "history" ||
|
||||
lowerAction === "changelog" ||
|
||||
lowerAction === "log" ||
|
||||
lowerAction === "history" ||
|
||||
booleanOption(args.options.changelog) === true;
|
||||
|
||||
const isCheck =
|
||||
action === "check" ||
|
||||
lowerAction === "check" ||
|
||||
booleanOption(args.options.check) === true ||
|
||||
booleanOption(args.options["check-only"]) === true;
|
||||
|
||||
|
||||
Reference in new issue
Block a user