@clerc/plugin-not-found 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var clerc = require('clerc');
6
+ var fastestLevenshtein = require('fastest-levenshtein');
7
+
8
+ const notFoundPlugin = () => clerc.definePlugin({
9
+ setup(cli) {
10
+ return cli.inspector((ctx, next) => {
11
+ try {
12
+ next();
13
+ } catch (e) {
14
+ if (!(e instanceof clerc.NoSuchCommandError)) {
15
+ throw e;
16
+ }
17
+ if (ctx.parameters.length === 0) {
18
+ console.log("No command given.");
19
+ console.log(`Possible commands: ${Object.keys(cli._commands).join(", ")}.`);
20
+ return;
21
+ }
22
+ const calledCommandName = e.message.replace("No such command: ", "");
23
+ const closestCommandName = fastestLevenshtein.closest(calledCommandName, Object.keys(cli._commands));
24
+ console.log(`Command "${calledCommandName}" not found.`);
25
+ console.log(`Did you mean "${closestCommandName}"?`);
26
+ }
27
+ });
28
+ }
29
+ });
30
+
31
+ exports.notFoundPlugin = notFoundPlugin;
@@ -0,0 +1,5 @@
1
+ import * as clerc from 'clerc';
2
+
3
+ declare const notFoundPlugin: () => clerc.Plugin<clerc.Clerc<{}>, clerc.Clerc<{}>>;
4
+
5
+ export { notFoundPlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,27 @@
1
+ import { definePlugin, NoSuchCommandError } from 'clerc';
2
+ import { closest } from 'fastest-levenshtein';
3
+
4
+ const notFoundPlugin = () => definePlugin({
5
+ setup(cli) {
6
+ return cli.inspector((ctx, next) => {
7
+ try {
8
+ next();
9
+ } catch (e) {
10
+ if (!(e instanceof NoSuchCommandError)) {
11
+ throw e;
12
+ }
13
+ if (ctx.parameters.length === 0) {
14
+ console.log("No command given.");
15
+ console.log(`Possible commands: ${Object.keys(cli._commands).join(", ")}.`);
16
+ return;
17
+ }
18
+ const calledCommandName = e.message.replace("No such command: ", "");
19
+ const closestCommandName = closest(calledCommandName, Object.keys(cli._commands));
20
+ console.log(`Command "${calledCommandName}" not found.`);
21
+ console.log(`Did you mean "${closestCommandName}"?`);
22
+ }
23
+ });
24
+ }
25
+ });
26
+
27
+ export { notFoundPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-not-found",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
5
5
  "description": "Clerc plugin not found (did you mean)",
6
6
  "keywords": [
@@ -43,8 +43,8 @@
43
43
  "clerc": "*"
44
44
  },
45
45
  "dependencies": {
46
- "@clerc/utils": "0.4.0",
47
- "clerc": "0.4.0",
46
+ "@clerc/utils": "0.5.0",
47
+ "clerc": "0.5.0",
48
48
  "fastest-levenshtein": "^1.0.16",
49
49
  "picocolors": "^1.0.0"
50
50
  },