cli-argv-util 1.2.4 → 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/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022-2023 Individual contributors to cli-argv-util
3
+ Copyright (c) 2022-2024 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
  [![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
@@ -23,22 +23,27 @@ Place the following code in your **bin/cli.js** file
23
23
  import { cliArgvUtil } from 'cli-argv-util';
24
24
 
25
25
  const validFlags = ['cd', 'find', 'no-summary'];
26
- const cli = cliArgvUtil.parse(validFlags);
27
- if (cliArgvUtil.invalidFlag)
28
- throw Error(cliArgvUtil.invalidFlagMsg);
26
+ const cli = cliArgvUtil.parse(validFlags);
27
+ if (cli.invalidFlag)
28
+ throw new Error(cli.invalidFlagMsg);
29
+ if (cli.flagOn.find)
30
+ console.log('You set the --find CLI flag to:', cli.flagMap.find);
31
+ if (cli.flagOn.noSummary)
32
+ console.log('You enabled the --no-summary CLI option.');
33
+ console.log('You supplied', cli.params.length , 'CLI parameter(s).');
29
34
  ```
30
- 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)
31
37
 
32
38
  If your CLI tool is named `my-program` and a user runs it like:
33
39
  ```shell
34
- $ my-program file.html --cd=src --no-summary file.png
40
+ $ my-program about.html --cd=src --no-summary 'Hello World' 777
35
41
  ```
36
42
  the resulting `cli` object will be:
37
43
  ```javascript
38
44
  {
39
45
  flagMap: {
40
- cd: 'src',
41
- noSummary: undefined,
46
+ cd: 'src',
42
47
  },
43
48
  flagOn: {
44
49
  cd: true,
@@ -47,9 +52,10 @@ the resulting `cli` object will be:
47
52
  },
48
53
  invalidFlag: null,
49
54
  invalidFlagMsg: null,
50
- params: ['file.html', 'file.png'],
55
+ params: ['about.html', 'Hello World', '777'],
51
56
  }
52
57
  ```
58
+ _**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
53
59
 
54
60
  ## C) Results
55
61
  The `cliArgvUtil.parse()` returns an object of type `Result`:
@@ -76,7 +82,7 @@ See the **TypeScript Declarations** at the top of [cli-argv-util.ts](cli-argv-ut
76
82
  - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):  _Run a command on each file in a folder and its subfolders_
77
83
  - 🔍 [replacer-util](https://github.com/center-key/replacer-util):  _Find and replace strings or template outputs in text files_
78
84
  - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):  _Revision web asset filenames with cache busting content hash fingerprints_
79
- - 🚆 [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_
80
86
  - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):  _Check the markup validity of HTML files using the W3C validator_
81
87
 
82
88
  Feel free to submit questions at:<br>
@@ -1,4 +1,4 @@
1
- //! cli-argv-util v1.2.4 ~~ 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.4 ~~ 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.4",
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.6",
84
- "@typescript-eslint/eslint-plugin": "~6.7",
85
- "@typescript-eslint/parser": "~6.7",
86
- "add-dist-header": "~1.3",
87
- "assert-deep-strict-equal": "~1.1",
88
- "copy-file-util": "~1.1",
89
- "eslint": "~8.50",
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.2"
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
  }