Skip to content

Commit

Permalink
feat: setup default commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed May 27, 2021
1 parent 5456dd0 commit cc0eeb9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/commands/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CAC } from "cac";
import exit from "exit";
import { logger, NAME } from "../lib";

export const _default = (cli: CAC, _: { [key: string]: never }): void => {
const command = cli.args.join(" ");

if (command) {
logger.error(
"Invalid command: `%s`, run `%s --help` for all commands",
command,
NAME
);
exit(1);
} else {
cli.outputHelp();
}
};
19 changes: 19 additions & 0 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import chalk from "chalk";
import { PACKAGE, VERSION } from "../lib";

interface HelpSection {
title?: string;
body: string;
}

export const help = (sections: HelpSection[]): void => {
sections.unshift({
body: `\n📚 Dico CLI\n ${chalk.cyanBright(
"Read the docs:"
)} https://docs.dico.app/cli`
});
sections[1].body = `Version:\n ${PACKAGE}@${VERSION}`;
sections[sections.length - 1].body = `${
sections[sections.length - 1].body
}\n`;
};
6 changes: 6 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./signin";
export * from "./signout";
export * from "./whoami";

export * from "./help";
export * from "./default";

0 comments on commit cc0eeb9

Please sign in to comment.