cli-argv-util 1.1.0 → 1.2.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 +0 -1
- package/dist/cli-argv-util.d.ts +4 -1
- package/dist/cli-argv-util.js +8 -3
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@ _Simple utility to parse command line parameters and flags (arguments vector)_
|
|
|
5
5
|
|
|
6
6
|
[](https://github.com/center-key/cli-argv-util/blob/main/LICENSE.txt)
|
|
7
7
|
[](https://www.npmjs.com/package/cli-argv-util)
|
|
8
|
-
[](https://snyk.io/test/github/center-key/cli-argv-util)
|
|
9
8
|
[](https://github.com/center-key/cli-argv-util/actions/workflows/run-spec-on-push.yaml)
|
|
10
9
|
|
|
11
10
|
**cli-argv-util** is called from your `bin/cli.js` file in order to read user
|
package/dist/cli-argv-util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! cli-argv-util v1.
|
|
1
|
+
//! cli-argv-util v1.2.0 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type StringFlagMap = {
|
|
4
4
|
[flag: string]: string | undefined;
|
|
@@ -16,5 +16,8 @@ export type Result = {
|
|
|
16
16
|
};
|
|
17
17
|
declare const cliArgvUtil: {
|
|
18
18
|
parse(validFlags: string[]): Result;
|
|
19
|
+
run(packageJson: {
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}, posix: string): Buffer;
|
|
19
22
|
};
|
|
20
23
|
export { cliArgvUtil };
|
package/dist/cli-argv-util.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
//! cli-argv-util v1.
|
|
1
|
+
//! cli-argv-util v1.2.0 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
|
|
2
2
|
|
|
3
|
+
import { execSync } from 'node:child_process';
|
|
3
4
|
const cliArgvUtil = {
|
|
4
5
|
parse(validFlags) {
|
|
5
|
-
var _a, _b;
|
|
6
6
|
const toCamel = (token) => token.replace(/-./g, char => char[1].toUpperCase());
|
|
7
7
|
const toEntry = (pair) => [toCamel(pair[0]), pair[1]];
|
|
8
8
|
const toPair = (flag) => flag.replace(/^--/, '').split('=');
|
|
@@ -10,7 +10,7 @@ const cliArgvUtil = {
|
|
|
10
10
|
const pairs = args.filter(arg => /^--/.test(arg)).map(toPair);
|
|
11
11
|
const flagMap = Object.fromEntries(pairs.map(toEntry));
|
|
12
12
|
const onEntries = validFlags.map(flag => [toCamel(flag), toCamel(flag) in flagMap]);
|
|
13
|
-
const invalidFlag =
|
|
13
|
+
const invalidFlag = pairs.find(pair => !validFlags.includes(pair[0]))?.[0] ?? null;
|
|
14
14
|
const helpMsg = '\nValid flags are --' + validFlags.join(' --');
|
|
15
15
|
const params = args.filter(arg => !/^--/.test(arg));
|
|
16
16
|
return {
|
|
@@ -22,5 +22,10 @@ const cliArgvUtil = {
|
|
|
22
22
|
paramCount: params.length,
|
|
23
23
|
};
|
|
24
24
|
},
|
|
25
|
+
run(packageJson, posix) {
|
|
26
|
+
const name = Object.keys(packageJson.bin).sort()[0];
|
|
27
|
+
const command = process.platform === 'win32' ? posix.replaceAll('\\ ', '" "') : posix;
|
|
28
|
+
return execSync(command.replace(name, 'node bin/cli.js'), { stdio: 'inherit' });
|
|
29
|
+
},
|
|
25
30
|
};
|
|
26
31
|
export { cliArgvUtil };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-argv-util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Simple utility to parse command line parameters and flags (arguments vector)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -72,17 +72,17 @@
|
|
|
72
72
|
"test": "mocha spec/*.spec.js"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@types/node": "~20.
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "~
|
|
77
|
-
"@typescript-eslint/parser": "~
|
|
78
|
-
"add-dist-header": "~1.
|
|
79
|
-
"assert-deep-strict-equal": "~1.
|
|
75
|
+
"@types/node": "~20.4",
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "~6.0",
|
|
77
|
+
"@typescript-eslint/parser": "~6.0",
|
|
78
|
+
"add-dist-header": "~1.1",
|
|
79
|
+
"assert-deep-strict-equal": "~1.1",
|
|
80
80
|
"copy-file-util": "~1.1",
|
|
81
|
-
"eslint": "~8.
|
|
81
|
+
"eslint": "~8.44",
|
|
82
82
|
"jshint": "~2.13",
|
|
83
83
|
"mocha": "~10.2",
|
|
84
84
|
"rimraf": "~5.0",
|
|
85
|
-
"run-scripts-util": "~1.
|
|
85
|
+
"run-scripts-util": "~1.2",
|
|
86
86
|
"typescript": "~5.1"
|
|
87
87
|
}
|
|
88
88
|
}
|