cli-argv-util 1.2.5 → 1.2.6

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 CHANGED
@@ -5,7 +5,7 @@ _Simple utility to parse command line parameters and flags (arguments vector)_
5
5
 
6
6
  [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/cli-argv-util/blob/main/LICENSE.txt)
7
7
  [![npm](https://img.shields.io/npm/v/cli-argv-util.svg)](https://www.npmjs.com/package/cli-argv-util)
8
- [![Build](https://github.com/center-key/cli-argv-util/workflows/build/badge.svg)](https://github.com/center-key/cli-argv-util/actions/workflows/run-spec-on-push.yaml)
8
+ [![Build](https://github.com/center-key/cli-argv-util/actions/workflows/run-spec-on-push.yaml/badge.svg)](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: [cli.js](https://github.com/center-key/copy-file-util/blob/main/bin/cli.js)
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
@@ -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 named groups of easy to manage commands_
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>
@@ -1,4 +1,4 @@
1
- //! cli-argv-util v1.2.5 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
1
+ //! cli-argv-util v1.2.6 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
2
2
 
3
3
  export type StringFlagMap = {
4
4
  [flag: string]: string | undefined;
@@ -1,4 +1,4 @@
1
- //! cli-argv-util v1.2.5 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
1
+ //! cli-argv-util v1.2.6 ~~ 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: Object.fromEntries(onEntries),
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] + ' ' + arg;
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.5",
3
+ "version": "1.2.6",
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 . --ext .ts"
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
- "@types/node": "~20.10",
84
- "@typescript-eslint/eslint-plugin": "~6.17",
85
- "@typescript-eslint/parser": "~6.17",
86
- "add-dist-header": "~1.3",
87
- "assert-deep-strict-equal": "~1.1",
88
- "copy-file-util": "~1.1",
89
- "eslint": "~8.56",
58
+ "@eslint/js": "~9.9",
59
+ "@types/node": "~22.3",
60
+ "add-dist-header": "~1.4",
61
+ "assert-deep-strict-equal": "~1.2",
62
+ "copy-file-util": "~1.2",
63
+ "eslint": "~9.9",
90
64
  "jshint": "~2.13",
91
- "mocha": "~10.2",
92
- "rimraf": "~5.0",
93
- "run-scripts-util": "~1.2",
94
- "typescript": "~5.3"
65
+ "mocha": "~10.7",
66
+ "rimraf": "~6.0",
67
+ "run-scripts-util": "~1.3",
68
+ "typescript": "~5.5",
69
+ "typescript-eslint": "~8.1"
95
70
  }
96
71
  }