cli-argv-util 1.3.0 → 1.4.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 +5 -4
- package/dist/cli-argv-util.d.ts +9 -2
- package/dist/cli-argv-util.js +13 -1
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -27,10 +27,10 @@ const cli = cliArgvUtil.parse(validFlags);
|
|
|
27
27
|
if (cli.invalidFlag)
|
|
28
28
|
throw new Error(cli.invalidFlagMsg);
|
|
29
29
|
if (cli.flagOn.find)
|
|
30
|
-
console.
|
|
30
|
+
console.info('You set the --find CLI flag to:', cli.flagMap.find);
|
|
31
31
|
if (cli.flagOn.noSummary)
|
|
32
|
-
console.
|
|
33
|
-
console.
|
|
32
|
+
console.info('You enabled the --no-summary CLI option.');
|
|
33
|
+
console.info('You supplied', cli.params.length , 'CLI parameter(s).');
|
|
34
34
|
```
|
|
35
35
|
For a real world example, see:
|
|
36
36
|
[cli.js](https://github.com/center-key/copy-file-util/blob/main/bin/cli.js)
|
|
@@ -55,7 +55,8 @@ the resulting `cli` object will be:
|
|
|
55
55
|
params: ['about.html', 'Hello World', '777'],
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
|
-
|
|
58
|
+
> [!NOTE]
|
|
59
|
+
> _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
|
|
59
60
|
|
|
60
61
|
## C) Results
|
|
61
62
|
The `cliArgvUtil.parse()` returns an object of type `Result`:
|
package/dist/cli-argv-util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! cli-argv-util v1.
|
|
1
|
+
//! cli-argv-util v1.4.0 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type StringFlagMap = {
|
|
4
4
|
[flag: string]: string | undefined;
|
|
@@ -6,6 +6,12 @@ export type StringFlagMap = {
|
|
|
6
6
|
export type BooleanFlagMap = {
|
|
7
7
|
[flag: string]: boolean;
|
|
8
8
|
};
|
|
9
|
+
export type Ancestor = {
|
|
10
|
+
common: string;
|
|
11
|
+
source: string;
|
|
12
|
+
target: string;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
9
15
|
export type Result = {
|
|
10
16
|
flagMap: StringFlagMap;
|
|
11
17
|
flagOn: BooleanFlagMap;
|
|
@@ -18,9 +24,10 @@ declare const cliArgvUtil: {
|
|
|
18
24
|
parse(validFlags: string[]): Result;
|
|
19
25
|
run(packageJson: {
|
|
20
26
|
[key: string]: unknown;
|
|
21
|
-
}, posix: string):
|
|
27
|
+
}, posix: string): NonSharedBuffer;
|
|
22
28
|
readFolder(folder: string): string[];
|
|
23
29
|
cleanPath(name: string): string;
|
|
30
|
+
calcAncestor(sourceFile: string, targetFile: string): Ancestor;
|
|
24
31
|
unquoteArgs(args: string[]): string[];
|
|
25
32
|
};
|
|
26
33
|
export { cliArgvUtil };
|
package/dist/cli-argv-util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
//! cli-argv-util v1.
|
|
1
|
+
//! cli-argv-util v1.4.0 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { execSync } from 'node:child_process';
|
|
4
|
+
import chalk from 'chalk';
|
|
4
5
|
import fs from 'fs';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
import slash from 'slash';
|
|
@@ -37,6 +38,17 @@ const cliArgvUtil = {
|
|
|
37
38
|
cleanPath(name) {
|
|
38
39
|
return slash(path.normalize(name)).trim().replace(/\/$/, '');
|
|
39
40
|
},
|
|
41
|
+
calcAncestor(sourceFile, targetFile) {
|
|
42
|
+
const index = Array.from(sourceFile).findIndex((char, i) => targetFile[i] !== char);
|
|
43
|
+
const substr = index === -1 ? sourceFile : sourceFile.substring(0, index);
|
|
44
|
+
const common = sourceFile.substring(0, substr.lastIndexOf('/'));
|
|
45
|
+
const len = common.length ? common.length + 1 : 0;
|
|
46
|
+
const source = sourceFile.substring(len);
|
|
47
|
+
const target = targetFile.substring(len);
|
|
48
|
+
const intro = common ? chalk.blue(common) + chalk.gray.bold(': ') : '';
|
|
49
|
+
const message = intro + chalk.white(source) + chalk.gray.bold(' → ') + chalk.green(target);
|
|
50
|
+
return { common, source, target, message };
|
|
51
|
+
},
|
|
40
52
|
unquoteArgs(args) {
|
|
41
53
|
const unquote = (builder, nextArg) => {
|
|
42
54
|
const arg = nextArg.replace(/^'/, '').replace(/'$/, '');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-argv-util",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Simple utility to parse command line parameters and flags (arguments vector)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -49,23 +49,24 @@
|
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"pretest": "run-scripts clean lint build",
|
|
52
|
-
"test": "mocha spec
|
|
52
|
+
"test": "mocha spec"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
+
"chalk": "~5.6",
|
|
55
56
|
"slash": "~5.1"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@eslint/js": "~9.
|
|
59
|
-
"@types/node": "~
|
|
60
|
-
"add-dist-header": "~1.
|
|
59
|
+
"@eslint/js": "~9.39",
|
|
60
|
+
"@types/node": "~25.0",
|
|
61
|
+
"add-dist-header": "~1.6",
|
|
61
62
|
"assert-deep-strict-equal": "~1.2",
|
|
62
|
-
"copy-file-util": "~1.
|
|
63
|
-
"eslint": "~9.
|
|
63
|
+
"copy-file-util": "~1.3",
|
|
64
|
+
"eslint": "~9.39",
|
|
64
65
|
"jshint": "~2.13",
|
|
65
66
|
"mocha": "~11.7",
|
|
66
|
-
"rimraf": "~6.
|
|
67
|
+
"rimraf": "~6.1",
|
|
67
68
|
"run-scripts-util": "~1.3",
|
|
68
|
-
"typescript": "~5.
|
|
69
|
-
"typescript-eslint": "~8.
|
|
69
|
+
"typescript": "~5.9",
|
|
70
|
+
"typescript-eslint": "~8.49"
|
|
70
71
|
}
|
|
71
72
|
}
|