@clerc/plugin-strict-flags 0.40.0 → 0.42.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/README.md +25 -0
- package/dist/index.js +62 -1
- package/package.json +14 -14
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @clerc/plugin-strict-flags
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@clerc/plugin-strict-flags)
|
|
4
|
+
|
|
5
|
+
Clerc plugin to throw error when unknown flags are passed.
|
|
6
|
+
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ npm install @clerc/plugin-strict-flags
|
|
11
|
+
$ yarn add @clerc/plugin-strict-flags
|
|
12
|
+
$ pnpm add @clerc/plugin-strict-flags
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 🚀 Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { strictFlagsPlugin } from "@clerc/plugin-strict-flags";
|
|
19
|
+
|
|
20
|
+
cli.use(strictFlagsPlugin());
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 📝 License
|
|
24
|
+
|
|
25
|
+
[MIT](../../LICENSE). Made with ❤️ by [Ray](https://github.com/so1ve)
|
package/dist/index.js
CHANGED
|
@@ -1 +1,62 @@
|
|
|
1
|
-
import{definePlugin
|
|
1
|
+
import { definePlugin } from '@clerc/core';
|
|
2
|
+
|
|
3
|
+
const locales$1 = {
|
|
4
|
+
"en": {
|
|
5
|
+
"utils.and": "%s and %s"
|
|
6
|
+
},
|
|
7
|
+
"zh-CN": {
|
|
8
|
+
"utils.and": "%s \u548C %s"
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function semanticArray(array, { add, t }) {
|
|
12
|
+
add(locales$1);
|
|
13
|
+
if (array.length <= 1) {
|
|
14
|
+
return array[0];
|
|
15
|
+
}
|
|
16
|
+
return t(
|
|
17
|
+
"utils.and",
|
|
18
|
+
array.slice(0, -1).join(", "),
|
|
19
|
+
array[array.length - 1]
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const locales = {
|
|
24
|
+
"en": {
|
|
25
|
+
"strictFlags.unexpectedSingle": "Unexpected flag: %s.",
|
|
26
|
+
"strictFlags.unexpectedMore": "Unexpected flags: %s.",
|
|
27
|
+
"strictFlags.and": "%s and %s"
|
|
28
|
+
},
|
|
29
|
+
"zh-CN": {
|
|
30
|
+
"strictFlags.unexpectedSingle": "\u9884\u671F\u4E4B\u5916\u7684\u6807\u5FD7: %s\u3002",
|
|
31
|
+
"strictFlags.unexpectedMore": "\u9884\u671F\u4E4B\u5916\u7684\u6807\u5FD7: %s\u3002",
|
|
32
|
+
"strictFlags.and": "%s \u548C %s"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const strictFlagsPlugin = () => definePlugin({
|
|
37
|
+
setup: (cli) => {
|
|
38
|
+
const { add, t } = cli.i18n;
|
|
39
|
+
add(locales);
|
|
40
|
+
return cli.inspector((context, next) => {
|
|
41
|
+
const keys = Object.keys(context.unknownFlags);
|
|
42
|
+
if (!context.resolved || keys.length === 0) {
|
|
43
|
+
next();
|
|
44
|
+
} else {
|
|
45
|
+
const error = keys.length > 1 ? new Error(
|
|
46
|
+
t(
|
|
47
|
+
"strictFlags.unexpectedMore",
|
|
48
|
+
semanticArray(keys, cli.i18n)
|
|
49
|
+
)
|
|
50
|
+
) : new Error(
|
|
51
|
+
t(
|
|
52
|
+
"strictFlags.unexpectedSingle",
|
|
53
|
+
semanticArray(keys, cli.i18n)
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export { strictFlagsPlugin };
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-strict-flags",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"description": "Clerc plugin strict flags",
|
|
6
7
|
"keywords": [
|
|
7
|
-
"
|
|
8
|
-
"clerc",
|
|
9
|
-
"clerc-plugin",
|
|
8
|
+
"args",
|
|
10
9
|
"arguments",
|
|
11
10
|
"argv",
|
|
12
|
-
"
|
|
11
|
+
"clerc",
|
|
12
|
+
"clerc-plugin",
|
|
13
|
+
"cli",
|
|
13
14
|
"terminal"
|
|
14
15
|
],
|
|
15
|
-
"
|
|
16
|
-
"homepage": "https://github.com/so1ve/clerc/tree/main/packages/plugin-strict-flags#readme",
|
|
16
|
+
"homepage": "https://github.com/clercjs/clerc/tree/main/packages/plugin-strict-flags#readme",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
19
|
+
"url": "git+https://github.com/clercjs/clerc.git",
|
|
20
20
|
"directory": "/"
|
|
21
21
|
},
|
|
22
22
|
"bugs": {
|
|
23
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "https://github.com/clercjs/clerc/issues"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"sideEffects": false,
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@clerc/utils": "0.42.0",
|
|
52
|
+
"@clerc/core": "0.42.0"
|
|
53
|
+
},
|
|
50
54
|
"peerDependencies": {
|
|
51
55
|
"@clerc/core": "*"
|
|
52
56
|
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@clerc/core": "0.40.0",
|
|
55
|
-
"@clerc/utils": "0.40.0"
|
|
56
|
-
},
|
|
57
57
|
"scripts": {
|
|
58
|
-
"build": "pkgroll
|
|
58
|
+
"build": "pkgroll",
|
|
59
59
|
"watch": "pkgroll --watch"
|
|
60
60
|
}
|
|
61
61
|
}
|