@the-librarian/cli 1.16.1 → 1.17.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/dist/parse-args.d.ts +9 -1
- package/dist/parse-args.d.ts.map +1 -1
- package/dist/parse-args.js +55 -20
- package/dist/parse-args.js.map +1 -1
- package/package.json +1 -1
package/dist/parse-args.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ export interface ParsedArgs {
|
|
|
7
7
|
export declare function parseArgs(args: string[]): ParsedArgs;
|
|
8
8
|
/** Coerce a flag to a string, or undefined when it isn't a plain string. */
|
|
9
9
|
export declare function flagString(value: FlagValue | undefined): string | undefined;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* True iff the flag reads as on: a bare `--foo`, or an inline `--foo=true`.
|
|
12
|
+
*
|
|
13
|
+
* The inline arm matters because this parser has no switch registry, so
|
|
14
|
+
* `--yes=true` arrives as the STRING "true" (spec 073). Comparing to `true`
|
|
15
|
+
* alone would read that as off and silently prompt anyway — the operator having
|
|
16
|
+
* plainly said otherwise. `flagBool` is the single reader of every switch here,
|
|
17
|
+
* so this is the one place the interpretation belongs.
|
|
18
|
+
*/
|
|
11
19
|
export declare function flagBool(value: FlagValue | undefined): boolean;
|
|
12
20
|
//# sourceMappingURL=parse-args.d.ts.map
|
package/dist/parse-args.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-args.d.ts","sourceRoot":"","sources":["../src/parse-args.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;AACpD,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"parse-args.d.ts","sourceRoot":"","sources":["../src/parse-args.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC;AACpD,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;CAChB;AAmBD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAqCpD;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAU9D"}
|
package/dist/parse-args.js
CHANGED
|
@@ -4,6 +4,25 @@
|
|
|
4
4
|
// `parseArgs(argv)` splits a verb's arguments into `{ positionals, flags }`.
|
|
5
5
|
// Bare `--foo` → `true`; `--no-foo` → `false`; `--foo bar` → `"bar"`;
|
|
6
6
|
// repeated `--foo a --foo b` → `["a", "b"]`.
|
|
7
|
+
/**
|
|
8
|
+
* Record a flag value, collecting repeats into an array. Shared by the spaced
|
|
9
|
+
* (`--tag a`) and inline (`--tag=a`) forms so the two cannot drift.
|
|
10
|
+
*/
|
|
11
|
+
function assignFlag(flags, key, value) {
|
|
12
|
+
const existing = flags[key];
|
|
13
|
+
if (existing === undefined) {
|
|
14
|
+
flags[key] = value;
|
|
15
|
+
}
|
|
16
|
+
else if (Array.isArray(existing)) {
|
|
17
|
+
existing.push(value);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof existing === "string") {
|
|
20
|
+
flags[key] = [existing, value];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
flags[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
export function parseArgs(args) {
|
|
8
27
|
const positionals = [];
|
|
9
28
|
const flags = {};
|
|
@@ -11,30 +30,30 @@ export function parseArgs(args) {
|
|
|
11
30
|
const arg = args[i];
|
|
12
31
|
if (typeof arg !== "string")
|
|
13
32
|
continue;
|
|
14
|
-
if (arg.startsWith("--no-")) {
|
|
15
|
-
flags[arg.slice("--no-".length)] = false;
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
33
|
if (arg.startsWith("--")) {
|
|
19
|
-
|
|
34
|
+
// Split `--key=value` on the FIRST `=` (spec 073). Without this the whole
|
|
35
|
+
// `key=value` string became the flag NAME set to true, leaving the real
|
|
36
|
+
// flag unset — so `--data-dir=/srv/x` ran against the default without a
|
|
37
|
+
// word. Mirrors packages/cli/parse-flags.ts; the two must agree on what a
|
|
38
|
+
// flag looks like.
|
|
39
|
+
const body = arg.slice(2);
|
|
40
|
+
const equals = body.indexOf("=");
|
|
41
|
+
const key = equals === -1 ? body : body.slice(0, equals);
|
|
42
|
+
const inlineValue = equals === -1 ? null : body.slice(equals + 1);
|
|
43
|
+
if (key.startsWith("no-")) {
|
|
44
|
+
flags[key.slice("no-".length)] = false;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (inlineValue !== null) {
|
|
48
|
+
assignFlag(flags, key, inlineValue);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
20
51
|
const next = args[i + 1];
|
|
21
52
|
if (next === undefined || (typeof next === "string" && next.startsWith("--"))) {
|
|
22
53
|
flags[key] = true;
|
|
23
54
|
}
|
|
24
55
|
else {
|
|
25
|
-
|
|
26
|
-
if (existing === undefined) {
|
|
27
|
-
flags[key] = next;
|
|
28
|
-
}
|
|
29
|
-
else if (Array.isArray(existing)) {
|
|
30
|
-
existing.push(next);
|
|
31
|
-
}
|
|
32
|
-
else if (typeof existing === "string") {
|
|
33
|
-
flags[key] = [existing, next];
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
flags[key] = next;
|
|
37
|
-
}
|
|
56
|
+
assignFlag(flags, key, next);
|
|
38
57
|
i += 1;
|
|
39
58
|
}
|
|
40
59
|
continue;
|
|
@@ -47,8 +66,24 @@ export function parseArgs(args) {
|
|
|
47
66
|
export function flagString(value) {
|
|
48
67
|
return typeof value === "string" ? value : undefined;
|
|
49
68
|
}
|
|
50
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* True iff the flag reads as on: a bare `--foo`, or an inline `--foo=true`.
|
|
71
|
+
*
|
|
72
|
+
* The inline arm matters because this parser has no switch registry, so
|
|
73
|
+
* `--yes=true` arrives as the STRING "true" (spec 073). Comparing to `true`
|
|
74
|
+
* alone would read that as off and silently prompt anyway — the operator having
|
|
75
|
+
* plainly said otherwise. `flagBool` is the single reader of every switch here,
|
|
76
|
+
* so this is the one place the interpretation belongs.
|
|
77
|
+
*/
|
|
51
78
|
export function flagBool(value) {
|
|
52
|
-
|
|
79
|
+
if (value === true)
|
|
80
|
+
return true;
|
|
81
|
+
if (typeof value !== "string")
|
|
82
|
+
return false;
|
|
83
|
+
const normalized = value.trim().toLowerCase();
|
|
84
|
+
return !(normalized === "false" ||
|
|
85
|
+
normalized === "0" ||
|
|
86
|
+
normalized === "no" ||
|
|
87
|
+
normalized === "");
|
|
53
88
|
}
|
|
54
89
|
//# sourceMappingURL=parse-args.js.map
|
package/dist/parse-args.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-args.js","sourceRoot":"","sources":["../src/parse-args.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,uDAAuD;AACvD,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AACtE,6CAA6C;AAU7C,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,KAAK,GAAY,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC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