Skip to content

Commit c7a4327

Browse files
committed
✨refactor(feature): 默认命令处理
1 parent 2ec0440 commit c7a4327

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/cli.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import cac from "cac";
1+
import cac, { CAC } from "cac";
22

33
import { handleError } from "@/shared/index";
44
import { commandSet } from "@/setup";
55

66
import { version } from "../package.json";
77

8+
function welcome(cli: CAC) {
9+
cli.outputHelp();
10+
}
11+
812
export const setupCli = async () => {
913
const cli = cac("cg");
1014

@@ -15,7 +19,16 @@ export const setupCli = async () => {
1519
cli.help();
1620
cli.version(version);
1721

22+
cli.on("command:!", () => {
23+
welcome(cli);
24+
});
25+
26+
cli.on("command:*", () => {
27+
welcome(cli);
28+
});
29+
1830
cli.parse(process.argv, { run: false });
31+
1932
await cli.runMatchedCommand();
2033
};
2134

src/setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { npmRegistry } from "./command/npm-registry";
2424
import { createProject } from "./command/create-project";
2525

2626
export const commandSet: CommandSet = {
27+
defaultCmd: (cli: CAC) => {
28+
cli.command("");
29+
},
2730
gitCommitCmd: (cli: CAC) => {
2831
cli
2932
.command("commit", "生成 angualr 规范的提交信息")

src/shared/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class PrettyError extends Error {
3030
}
3131

3232
export function handleError(error: unknown) {
33-
if (error instanceof PrettyError) loggerError(error);
33+
if (error instanceof PrettyError) printError(error);
3434
process.exitCode = 1;
3535
}
3636

0 commit comments

Comments
 (0)