Skip to content

Commit

Permalink
feat(not-found): add color for not found plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve committed Nov 28, 2022
1 parent 4cf1e04 commit 5382442
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/plugin-not-found/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TODO: unit tests
import { NoSuchCommandError, definePlugin } from "clerc";
import { closest } from "fastest-levenshtein";
import pc from "picocolors";

export const notFoundPlugin = () => definePlugin({
setup (cli) {
Expand All @@ -12,14 +13,14 @@ export const notFoundPlugin = () => definePlugin({
if (!(e instanceof NoSuchCommandError)) { throw e; }
if (ctx.parameters.length === 0) {
console.log("No command given.");
console.log(`Possible commands: ${Object.keys(cli._commands).join(", ")}.`);
console.log(`Possible commands: ${pc.bold(Object.keys(cli._commands).join(", "))}.`);
return;
}
// Bad example :(
const calledCommandName = e.message.replace("No such command: ", "");
const closestCommandName = closest(calledCommandName, Object.keys(cli._commands));
console.log(`Command "${calledCommandName}" not found.`);
console.log(`Did you mean "${closestCommandName}"?`);
console.log(`Command "${pc.strikethrough(calledCommandName)}" not found.`);
console.log(`Did you mean "${pc.bold(closestCommandName)}"?`);
}
});
},
Expand Down

0 comments on commit 5382442

Please sign in to comment.