Skip to content

Commit 7de2a6c

Browse files
authored
fix: show cli error message (#186)
1 parent 501b446 commit 7de2a6c

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export async function runMain<T extends ArgsDef = ArgsDef>(
3333
const isCLIError = error instanceof CLIError;
3434
if (isCLIError) {
3535
await showUsage(...(await resolveSubCommand(cmd, rawArgs)));
36+
consola.error(error.message);
3637
} else {
3738
consola.error(error, "\n");
3839
}

test/usage.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
import { expect, it, describe } from "vitest";
1+
import { expect, it, describe, vi } from "vitest";
22
import { renderUsage } from "../src/usage";
33
import { defineCommand } from "../src";
44

5+
vi.mock("consola/utils", async () => {
6+
const mod = await vi.importActual("consola/utils");
7+
8+
return {
9+
...mod,
10+
colors: {
11+
...mod.colors,
12+
underline: (val) => val,
13+
bold: (val) => val,
14+
gray: (val) => val,
15+
},
16+
};
17+
});
18+
519
describe("usage", () => {
620
it("renders arguments", async () => {
721
const command = defineCommand({

0 commit comments

Comments
 (0)