Skip to content

Commit cec6bfa

Browse files
committed
fix(core): should resolve alias from command object instead of options
1 parent 9e12eee commit cec6bfa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/core/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class Clerc<
225225
}
226226
: nameOrCommandObject;
227227

228-
const aliases = toArray(options?.alias ?? []);
228+
const aliases = toArray(command?.alias ?? []);
229229

230230
this.#callWithErrorHandler(() =>
231231
this.#validateCommandNameAndAlias(command.name, aliases),

packages/core/test/cli.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,19 @@ describe("cli", () => {
515515
})
516516
.parse(["foo", "baz"]);
517517
});
518+
519+
it("should resolve alias from command object", async () => {
520+
await expect(
521+
TestBaseCli()
522+
.command({
523+
name: "foo",
524+
description: "foo",
525+
alias: "bar",
526+
handler: (ctx) => {
527+
expect(ctx.command.name).toBe("foo");
528+
},
529+
})
530+
.parse(["bar"]),
531+
).resolves.not.toThrow();
532+
});
518533
});

0 commit comments

Comments
 (0)