Skip to content

Commit bd9b73f

Browse files
committed
Release v1.2.4
1 parent ebb2283 commit bd9b73f

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

dist/cli-argv-util.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! cli-argv-util v1.2.3 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
1+
//! cli-argv-util v1.2.4 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
22

33
export type StringFlagMap = {
44
[flag: string]: string | undefined;
@@ -20,5 +20,6 @@ declare const cliArgvUtil: {
2020
[key: string]: unknown;
2121
}, posix: string): Buffer;
2222
readFolder(folder: string): string[];
23+
unquoteArgs(args: string[]): string[];
2324
};
2425
export { cliArgvUtil };

dist/cli-argv-util.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! cli-argv-util v1.2.3 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
1+
//! cli-argv-util v1.2.4 ~~ https://github.com/center-key/cli-argv-util ~~ MIT License
22

33
import { execSync } from 'node:child_process';
44
import fs from 'fs';
@@ -8,17 +8,7 @@ const cliArgvUtil = {
88
const toCamel = (token) => token.replace(/-./g, char => char[1].toUpperCase());
99
const toEntry = (pair) => [toCamel(pair[0]), pair[1]];
1010
const toPair = (flag) => flag.replace(/^--/, '').split('=');
11-
const unquote = (builder, nextArg) => {
12-
const arg = nextArg.replace(/^'/, '').replace(/'$/, '');
13-
const last = builder[1].length - 1;
14-
if (builder[0])
15-
builder[1][last] = builder[1][last] + ' ' + arg;
16-
else
17-
builder[1].push(arg);
18-
const quoteMode = (/^'/.test(nextArg) || builder[0]) && !/'$/.test(nextArg);
19-
return [quoteMode, builder[1]];
20-
};
21-
const args = process.argv.slice(2).reduce(unquote, [false, []])[1];
11+
const args = cliArgvUtil.unquoteArgs(process.argv.slice(2));
2212
const pairs = args.filter(arg => /^--/.test(arg)).map(toPair);
2313
const flagMap = Object.fromEntries(pairs.map(toEntry));
2414
const onEntries = validFlags.map(flag => [toCamel(flag), toCamel(flag) in flagMap]);
@@ -42,5 +32,18 @@ const cliArgvUtil = {
4232
readFolder(folder) {
4333
return fs.readdirSync(folder, { recursive: true }).map(file => slash(String(file))).sort();
4434
},
35+
unquoteArgs(args) {
36+
const unquote = (builder, nextArg) => {
37+
const arg = nextArg.replace(/^'/, '').replace(/'$/, '');
38+
const last = builder[1].length - 1;
39+
if (builder[0])
40+
builder[1][last] = builder[1][last] + ' ' + arg;
41+
else
42+
builder[1].push(arg);
43+
const quoteMode = (/^'/.test(nextArg) || builder[0]) && !/'$/.test(nextArg);
44+
return [quoteMode, builder[1]];
45+
};
46+
return args.reduce(unquote, [false, []])[1];
47+
},
4548
};
4649
export { cliArgvUtil };

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cli-argv-util",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Simple utility to parse command line parameters and flags (arguments vector)",
55
"license": "MIT",
66
"type": "module",
@@ -16,7 +16,10 @@
1616
},
1717
"./": "./dist/"
1818
},
19-
"repository": "github:center-key/cli-argv-util",
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/center-key/cli-argv-util.git"
22+
},
2023
"homepage": "https://github.com/center-key/cli-argv-util",
2124
"bugs": "https://github.com/center-key/cli-argv-util/issues",
2225
"docs": "https://github.com/center-key/cli-argv-util#readme",

0 commit comments

Comments
 (0)