cli-argv-util 1.2.5 → 1.2.7
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/LICENSE.txt +1 -1
- package/README.md +6 -5
- package/dist/cli-argv-util.d.ts +2 -2
- package/dist/cli-argv-util.js +4 -3
- package/package.json +14 -39
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
3
|
+
Copyright (c) 2022-2025 Individual contributors to cli-argv-util
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ _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://github.com/center-key/cli-argv-util/actions/workflows/run-spec-on-push.yaml)
|
|
9
9
|
|
|
10
10
|
**cli-argv-util** is called from your `bin/cli.js` file in order to read user
|
|
11
11
|
supplied information on the command line and return the flags and parameters
|
|
@@ -25,14 +25,15 @@ import { cliArgvUtil } from 'cli-argv-util';
|
|
|
25
25
|
const validFlags = ['cd', 'find', 'no-summary'];
|
|
26
26
|
const cli = cliArgvUtil.parse(validFlags);
|
|
27
27
|
if (cli.invalidFlag)
|
|
28
|
-
throw Error(cli.invalidFlagMsg);
|
|
28
|
+
throw new Error(cli.invalidFlagMsg);
|
|
29
29
|
if (cli.flagOn.find)
|
|
30
30
|
console.log('You set the --find CLI flag to:', cli.flagMap.find);
|
|
31
31
|
if (cli.flagOn.noSummary)
|
|
32
32
|
console.log('You enabled the --no-summary CLI option.');
|
|
33
33
|
console.log('You supplied', cli.params.length , 'CLI parameter(s).');
|
|
34
34
|
```
|
|
35
|
-
For a real world example, see:
|
|
35
|
+
For a real world example, see:
|
|
36
|
+
[cli.js](https://github.com/center-key/copy-file-util/blob/main/bin/cli.js)
|
|
36
37
|
|
|
37
38
|
If your CLI tool is named `my-program` and a user runs it like:
|
|
38
39
|
```shell
|
|
@@ -69,7 +70,7 @@ export type Result = {
|
|
|
69
70
|
params: string[], //array of parameter values supplied by the user
|
|
70
71
|
};
|
|
71
72
|
```
|
|
72
|
-
See the **TypeScript Declarations** at the top of [cli-argv-util.ts](cli-argv-util.ts) for documentation.
|
|
73
|
+
See the **TypeScript Declarations** at the top of [cli-argv-util.ts](src/cli-argv-util.ts) for documentation.
|
|
73
74
|
|
|
74
75
|
<br>
|
|
75
76
|
|
|
@@ -81,7 +82,7 @@ See the **TypeScript Declarations** at the top of [cli-argv-util.ts](cli-argv-ut
|
|
|
81
82
|
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
|
|
82
83
|
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
|
|
83
84
|
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
|
|
84
|
-
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm scripts into
|
|
85
|
+
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into groups of easy to manage commands_
|
|
85
86
|
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
|
|
86
87
|
|
|
87
88
|
Feel free to submit questions at:<br>
|
package/dist/cli-argv-util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! cli-argv-util v1.2.
|
|
1
|
+
//! cli-argv-util v1.2.7 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
export type StringFlagMap = {
|
|
4
4
|
[flag: string]: string | undefined;
|
|
@@ -18,7 +18,7 @@ declare const cliArgvUtil: {
|
|
|
18
18
|
parse(validFlags: string[]): Result;
|
|
19
19
|
run(packageJson: {
|
|
20
20
|
[key: string]: unknown;
|
|
21
|
-
}, posix: string): Buffer
|
|
21
|
+
}, posix: string): Buffer<ArrayBufferLike>;
|
|
22
22
|
readFolder(folder: string): string[];
|
|
23
23
|
unquoteArgs(args: string[]): string[];
|
|
24
24
|
};
|
package/dist/cli-argv-util.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! cli-argv-util v1.2.
|
|
1
|
+
//! cli-argv-util v1.2.7 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
|
|
2
2
|
|
|
3
3
|
import { execSync } from 'node:child_process';
|
|
4
4
|
import fs from 'fs';
|
|
@@ -12,12 +12,13 @@ const cliArgvUtil = {
|
|
|
12
12
|
const pairs = args.filter(arg => /^--/.test(arg)).map(toPair);
|
|
13
13
|
const flagMap = Object.fromEntries(pairs.map(toEntry));
|
|
14
14
|
const onEntries = validFlags.map(flag => [toCamel(flag), toCamel(flag) in flagMap]);
|
|
15
|
+
const flagOn = Object.fromEntries(onEntries);
|
|
15
16
|
const invalidFlag = pairs.find(pair => !validFlags.includes(pair[0]))?.[0] ?? null;
|
|
16
17
|
const helpMsg = '\nValid flags are --' + validFlags.join(' --');
|
|
17
18
|
const params = args.filter(arg => !/^--/.test(arg));
|
|
18
19
|
return {
|
|
19
20
|
flagMap: flagMap,
|
|
20
|
-
flagOn:
|
|
21
|
+
flagOn: flagOn,
|
|
21
22
|
invalidFlag: invalidFlag,
|
|
22
23
|
invalidFlagMsg: invalidFlag ? 'Invalid flag: --' + invalidFlag + helpMsg : null,
|
|
23
24
|
params: params,
|
|
@@ -37,7 +38,7 @@ const cliArgvUtil = {
|
|
|
37
38
|
const arg = nextArg.replace(/^'/, '').replace(/'$/, '');
|
|
38
39
|
const last = builder[1].length - 1;
|
|
39
40
|
if (builder[0])
|
|
40
|
-
builder[1][last] = builder[1][last]
|
|
41
|
+
builder[1][last] = `${builder[1][last]} ${arg}`;
|
|
41
42
|
else
|
|
42
43
|
builder[1].push(arg);
|
|
43
44
|
const quoteMode = (/^'/.test(nextArg) || builder[0]) && !/'$/.test(nextArg);
|
package/package.json
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-argv-util",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "Simple utility to parse command line parameters and flags (arguments vector)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "dist/cli-argv-util.js",
|
|
8
|
-
"main": "dist/cli-argv-util.js",
|
|
9
8
|
"types": "dist/cli-argv-util.d.ts",
|
|
9
|
+
"exports": "./dist/cli-argv-util.js",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"import": "./dist/cli-argv-util.js"
|
|
16
|
-
},
|
|
17
|
-
"./": "./dist/"
|
|
18
|
-
},
|
|
19
13
|
"repository": {
|
|
20
14
|
"type": "git",
|
|
21
15
|
"url": "git+https://github.com/center-key/cli-argv-util.git"
|
|
@@ -40,32 +34,13 @@
|
|
|
40
34
|
"node": true,
|
|
41
35
|
"mocha": true
|
|
42
36
|
},
|
|
43
|
-
"eslintConfig": {
|
|
44
|
-
"ignorePatterns": [
|
|
45
|
-
"build",
|
|
46
|
-
"dist",
|
|
47
|
-
"node_modules"
|
|
48
|
-
],
|
|
49
|
-
"root": true,
|
|
50
|
-
"parser": "@typescript-eslint/parser",
|
|
51
|
-
"plugins": [
|
|
52
|
-
"@typescript-eslint"
|
|
53
|
-
],
|
|
54
|
-
"extends": [
|
|
55
|
-
"eslint:recommended",
|
|
56
|
-
"plugin:@typescript-eslint/recommended"
|
|
57
|
-
],
|
|
58
|
-
"rules": {
|
|
59
|
-
"@typescript-eslint/no-non-null-assertion": "off"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
37
|
"runScriptsConfig": {
|
|
63
38
|
"clean": [
|
|
64
39
|
"rimraf build dist"
|
|
65
40
|
],
|
|
66
41
|
"lint": [
|
|
67
42
|
"jshint . --exclude-path .gitignore",
|
|
68
|
-
"eslint --max-warnings 0
|
|
43
|
+
"eslint --max-warnings 0"
|
|
69
44
|
],
|
|
70
45
|
"build": [
|
|
71
46
|
"tsc",
|
|
@@ -80,17 +55,17 @@
|
|
|
80
55
|
"slash": "~5.1"
|
|
81
56
|
},
|
|
82
57
|
"devDependencies": {
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"eslint": "~8.56",
|
|
58
|
+
"@eslint/js": "~9.21",
|
|
59
|
+
"@types/node": "~22.13",
|
|
60
|
+
"add-dist-header": "~1.4",
|
|
61
|
+
"assert-deep-strict-equal": "~1.2",
|
|
62
|
+
"copy-file-util": "~1.2",
|
|
63
|
+
"eslint": "~9.21",
|
|
90
64
|
"jshint": "~2.13",
|
|
91
|
-
"mocha": "~
|
|
92
|
-
"rimraf": "~
|
|
93
|
-
"run-scripts-util": "~1.
|
|
94
|
-
"typescript": "~5.
|
|
65
|
+
"mocha": "~11.1",
|
|
66
|
+
"rimraf": "~6.0",
|
|
67
|
+
"run-scripts-util": "~1.3",
|
|
68
|
+
"typescript": "~5.7",
|
|
69
|
+
"typescript-eslint": "~8.25"
|
|
95
70
|
}
|
|
96
71
|
}
|