Skip to content

Commit 32a66a3

Browse files
author
hirsch88
committed
Add error handling for not existing commands
1 parent 7278c5f commit 32a66a3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/console/commander.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ new LoggerConfig().configure();
2626

2727
figlet('console', (error: any, data: any) => {
2828
console.log(chalk.blue(data));
29-
console.log(chalk.green('➜ ') + chalk.bold(process.argv[2]));
30-
console.log();
3129

3230
// Find all command files
3331
glob(path.join(__dirname, '**/*Command.ts'), (err: any, matches: string[]) => {
3432
if (err) {
3533
console.log(err);
3634
return;
3735
}
36+
3837
const files = matches
3938
.filter(m => m.indexOf('/lib') < 0)
4039
.map(m => ({
@@ -43,6 +42,17 @@ figlet('console', (error: any, data: any) => {
4342
}));
4443

4544
const commands = files.map(f => require(f.path)[f.name]);
45+
const keys = commands.map(c => c.command);
46+
const key = process.argv[2];
47+
48+
if (keys.indexOf(key) < 0) {
49+
console.log(chalk.red('➜ ') + chalk.bold(`Command ${key} was not found!`));
50+
console.log();
51+
return;
52+
}
53+
54+
console.log(chalk.green('➜ ') + chalk.bold(key));
55+
console.log();
4656

4757
commands.forEach((c) => {
4858
commander

0 commit comments

Comments
 (0)