clap-ts 0.3.0 → 0.4.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/parser.js +5 -5
- package/dist/types.d.ts +14 -1
- package/package.json +17 -1
- package/src/__tests__/arg-options.test.ts +687 -0
- package/src/__tests__/argfile.test.ts +127 -0
- package/src/__tests__/clap-parity.test.ts +682 -0
- package/src/__tests__/command-options.test.ts +713 -0
- package/src/__tests__/completions.test.ts +423 -0
- package/src/__tests__/config.test.ts +261 -0
- package/src/__tests__/deprecation.test.ts +104 -0
- package/src/__tests__/help.test.ts +312 -0
- package/src/__tests__/install.test.ts +120 -0
- package/src/__tests__/log.test.ts +189 -0
- package/src/__tests__/man.test.ts +135 -0
- package/src/__tests__/markdown.test.ts +114 -0
- package/src/__tests__/output.test.ts +249 -0
- package/src/__tests__/parser.test.ts +627 -0
- package/src/__tests__/plugins.test.ts +182 -0
- package/src/__tests__/progress.test.ts +221 -0
- package/src/__tests__/prompt.test.ts +265 -0
- package/src/__tests__/runner.test.ts +459 -0
- package/src/__tests__/spec.test.ts +107 -0
- package/src/__tests__/testing.test.ts +93 -0
- package/src/__tests__/validation.test.ts +267 -0
- package/src/argfile.ts +188 -0
- package/src/completions.ts +865 -0
- package/src/config.ts +184 -0
- package/src/help.ts +779 -0
- package/src/index.ts +58 -0
- package/src/install.ts +226 -0
- package/src/log.ts +225 -0
- package/src/man.ts +289 -0
- package/src/markdown.ts +210 -0
- package/src/output.ts +453 -0
- package/src/parser.ts +1240 -0
- package/src/plugins.ts +193 -0
- package/src/progress.ts +295 -0
- package/src/prompt.ts +388 -0
- package/src/runner.ts +769 -0
- package/src/spec.ts +197 -0
- package/src/testing.ts +159 -0
- package/src/types.ts +618 -0
- package/src/validation.ts +627 -0
package/dist/parser.js
CHANGED
|
@@ -38,14 +38,14 @@ export function getRawArgs(argv, noBinaryName = false) {
|
|
|
38
38
|
if (argv) {
|
|
39
39
|
return [...argv];
|
|
40
40
|
}
|
|
41
|
-
// Bun.argv
|
|
42
|
-
|
|
41
|
+
// `Bun.argv` is `process.argv`, and bun implements `process` in full, so
|
|
42
|
+
// reaching for the one when the other is there was a branch with two
|
|
43
|
+
// spellings of one answer.
|
|
44
|
+
const source = process.argv;
|
|
43
45
|
return noBinaryName ? [...source] : source.slice(2);
|
|
44
46
|
}
|
|
45
47
|
function readEnv(name) {
|
|
46
|
-
return
|
|
47
|
-
? process.env[name]
|
|
48
|
-
: globalThis.Bun.env[name];
|
|
48
|
+
return process.env[name];
|
|
49
49
|
}
|
|
50
50
|
// ---- Subcommands ----
|
|
51
51
|
const resolvedSubCommands = new WeakMap();
|
package/dist/types.d.ts
CHANGED
|
@@ -350,6 +350,17 @@ export interface ArgGroup {
|
|
|
350
350
|
/** Args that must be present when any member of this group is present. */
|
|
351
351
|
readonly requires?: readonly string[];
|
|
352
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* The value one arg parses to, given its action and its type.
|
|
355
|
+
*
|
|
356
|
+
* Taken apart from `InferArgValue` so that both unions reach a naked type
|
|
357
|
+
* parameter and the conditional distributes over them. `A['action']` is an
|
|
358
|
+
* indexed access, and a conditional on one of those tests the whole union at
|
|
359
|
+
* once: for a literal arg definition that is the same answer either way, but
|
|
360
|
+
* for `ArgDef` itself it is the difference between `string` and every value an
|
|
361
|
+
* arg can actually hold.
|
|
362
|
+
*/
|
|
363
|
+
type ArgValueOf<Act, Ty> = Act extends 'append' ? string[] : Act extends 'count' ? number : Ty extends 'boolean' ? boolean : Ty extends 'number' ? number : string;
|
|
353
364
|
/**
|
|
354
365
|
* Infer the parsed type from an ArgDef.
|
|
355
366
|
* - boolean -> boolean
|
|
@@ -357,8 +368,9 @@ export interface ArgGroup {
|
|
|
357
368
|
* - string/enum/positional -> string
|
|
358
369
|
* - action: 'append' -> string[]
|
|
359
370
|
* - action: 'count' -> number
|
|
371
|
+
* - ArgDef itself -> string | number | boolean | string[]
|
|
360
372
|
*/
|
|
361
|
-
export type InferArgValue<A extends ArgDef> = A['action']
|
|
373
|
+
export type InferArgValue<A extends ArgDef> = ArgValueOf<A['action'], A['type']>;
|
|
362
374
|
/**
|
|
363
375
|
* Infer whether an arg is optional based on required/default.
|
|
364
376
|
* Args with `required: true` are always non-optional.
|
|
@@ -524,3 +536,4 @@ export interface ParseResult {
|
|
|
524
536
|
/** Where each parsed value came from, by arg key. */
|
|
525
537
|
readonly valueSources: ReadonlyMap<string, ValueSource>;
|
|
526
538
|
}
|
|
539
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,70 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clap-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A type-safe CLI argument parser for TypeScript, inspired by Rust's clap crate. Full clap-style parsing, validation, help, subcommands, shell completions, man pages and markdown docs, with zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"source": "./src/index.ts",
|
|
6
7
|
"main": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
11
|
+
"source": "./src/index.ts",
|
|
10
12
|
"types": "./dist/index.d.ts",
|
|
11
13
|
"import": "./dist/index.js"
|
|
12
14
|
},
|
|
13
15
|
"./completions": {
|
|
16
|
+
"source": "./src/completions.ts",
|
|
14
17
|
"types": "./dist/completions.d.ts",
|
|
15
18
|
"import": "./dist/completions.js"
|
|
16
19
|
},
|
|
17
20
|
"./man": {
|
|
21
|
+
"source": "./src/man.ts",
|
|
18
22
|
"types": "./dist/man.d.ts",
|
|
19
23
|
"import": "./dist/man.js"
|
|
20
24
|
},
|
|
21
25
|
"./markdown": {
|
|
26
|
+
"source": "./src/markdown.ts",
|
|
22
27
|
"types": "./dist/markdown.d.ts",
|
|
23
28
|
"import": "./dist/markdown.js"
|
|
24
29
|
},
|
|
25
30
|
"./testing": {
|
|
31
|
+
"source": "./src/testing.ts",
|
|
26
32
|
"types": "./dist/testing.d.ts",
|
|
27
33
|
"import": "./dist/testing.js"
|
|
28
34
|
},
|
|
29
35
|
"./config": {
|
|
36
|
+
"source": "./src/config.ts",
|
|
30
37
|
"types": "./dist/config.d.ts",
|
|
31
38
|
"import": "./dist/config.js"
|
|
32
39
|
},
|
|
33
40
|
"./argfile": {
|
|
41
|
+
"source": "./src/argfile.ts",
|
|
34
42
|
"types": "./dist/argfile.d.ts",
|
|
35
43
|
"import": "./dist/argfile.js"
|
|
36
44
|
},
|
|
37
45
|
"./spec": {
|
|
46
|
+
"source": "./src/spec.ts",
|
|
38
47
|
"types": "./dist/spec.d.ts",
|
|
39
48
|
"import": "./dist/spec.js"
|
|
40
49
|
},
|
|
41
50
|
"./install": {
|
|
51
|
+
"source": "./src/install.ts",
|
|
42
52
|
"types": "./dist/install.d.ts",
|
|
43
53
|
"import": "./dist/install.js"
|
|
44
54
|
},
|
|
45
55
|
"./plugins": {
|
|
56
|
+
"source": "./src/plugins.ts",
|
|
46
57
|
"types": "./dist/plugins.d.ts",
|
|
47
58
|
"import": "./dist/plugins.js"
|
|
48
59
|
},
|
|
49
60
|
"./output": {
|
|
61
|
+
"source": "./src/output.ts",
|
|
50
62
|
"types": "./dist/output.d.ts",
|
|
51
63
|
"import": "./dist/output.js"
|
|
52
64
|
},
|
|
53
65
|
"./log": {
|
|
66
|
+
"source": "./src/log.ts",
|
|
54
67
|
"types": "./dist/log.d.ts",
|
|
55
68
|
"import": "./dist/log.js"
|
|
56
69
|
},
|
|
57
70
|
"./progress": {
|
|
71
|
+
"source": "./src/progress.ts",
|
|
58
72
|
"types": "./dist/progress.d.ts",
|
|
59
73
|
"import": "./dist/progress.js"
|
|
60
74
|
},
|
|
61
75
|
"./prompt": {
|
|
76
|
+
"source": "./src/prompt.ts",
|
|
62
77
|
"types": "./dist/prompt.d.ts",
|
|
63
78
|
"import": "./dist/prompt.js"
|
|
64
79
|
}
|
|
65
80
|
},
|
|
66
81
|
"files": [
|
|
67
82
|
"dist",
|
|
83
|
+
"src",
|
|
68
84
|
"LICENSE",
|
|
69
85
|
"README.md"
|
|
70
86
|
],
|