args-tokens 0.21.1 → 0.22.1
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/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArgToken, ParserOptions, parseArgs$1 as parseArgs } from "./parser-Cbxholql.js";
|
|
2
|
-
import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args,
|
|
2
|
+
import { ArgExplicitlyProvided, ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-BoS-UnqX.js";
|
|
3
3
|
|
|
4
4
|
//#region src/parse.d.ts
|
|
5
5
|
|
|
@@ -40,7 +40,7 @@ type ParsedArgs<A extends Args> = {
|
|
|
40
40
|
* Explicit provision status, same as `explicit` in {@link resolveArgs}.
|
|
41
41
|
* Indicates which arguments were explicitly provided vs using default values.
|
|
42
42
|
*/
|
|
43
|
-
explicit:
|
|
43
|
+
explicit: ArgExplicitlyProvided<A>;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
46
|
* Parse command line arguments.
|
|
@@ -59,4 +59,4 @@ type ParsedArgs<A extends Args> = {
|
|
|
59
59
|
*/
|
|
60
60
|
declare function parse<A extends Args>(args: string[], options?: ParseOptions<A>): ParsedArgs<A>;
|
|
61
61
|
//#endregion
|
|
62
|
-
export { ArgResolveError, ArgResolveErrorType, ArgSchema, ArgToken, ArgValues, Args, ParseOptions, ParsedArgs, ParserOptions, ResolveArgs, parse, parseArgs, resolveArgs };
|
|
62
|
+
export { type ArgExplicitlyProvided, ArgResolveError, type ArgResolveErrorType, type ArgSchema, type ArgToken, type ArgValues, type Args, type ParseOptions, type ParsedArgs, type ParserOptions, type ResolveArgs, parse, parseArgs, resolveArgs };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from "./parser-Dr4iAGaX.js";
|
|
2
2
|
import "./utils-N7UlhLbz.js";
|
|
3
|
-
import { ArgResolveError, resolveArgs } from "./resolver-
|
|
3
|
+
import { ArgResolveError, resolveArgs } from "./resolver-BsDoIgzu.js";
|
|
4
4
|
|
|
5
5
|
//#region src/parse.ts
|
|
6
6
|
const DEFAULT_OPTIONS = {
|
|
@@ -114,7 +114,7 @@ interface ResolveArgs {
|
|
|
114
114
|
* Each property indicates whether the corresponding argument was explicitly
|
|
115
115
|
* provided (true) or is using a default value or not provided (false).
|
|
116
116
|
*/
|
|
117
|
-
type
|
|
117
|
+
type ArgExplicitlyProvided<A extends Args> = { [K in keyof A]: boolean };
|
|
118
118
|
/**
|
|
119
119
|
* Resolve command line arguments.
|
|
120
120
|
* @param args - An arguments that contains {@link ArgSchema | arguments schema}.
|
|
@@ -153,7 +153,7 @@ declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], {
|
|
|
153
153
|
positionals: string[];
|
|
154
154
|
rest: string[];
|
|
155
155
|
error: AggregateError | undefined;
|
|
156
|
-
explicit:
|
|
156
|
+
explicit: ArgExplicitlyProvided<A>;
|
|
157
157
|
};
|
|
158
158
|
/**
|
|
159
159
|
* An error type for {@link ArgResolveError}.
|
|
@@ -170,4 +170,4 @@ declare class ArgResolveError extends Error {
|
|
|
170
170
|
constructor(message: string, name: string, type: ArgResolveErrorType, schema: ArgSchema);
|
|
171
171
|
}
|
|
172
172
|
//#endregion
|
|
173
|
-
export { ArgResolveError as ArgResolveError$1, ArgResolveErrorType, ArgSchema, ArgValues, Args,
|
|
173
|
+
export { ArgExplicitlyProvided, ArgResolveError as ArgResolveError$1, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs as resolveArgs$1 };
|
|
@@ -142,6 +142,22 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
142
142
|
for (const [rawArg, schema] of Object.entries(args)) {
|
|
143
143
|
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
|
|
144
144
|
explicit[rawArg] = false;
|
|
145
|
+
if (schema.type === "positional") {
|
|
146
|
+
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
|
|
147
|
+
if (schema.multiple) {
|
|
148
|
+
const remainingPositionals = positionalTokens.slice(positionalsCount);
|
|
149
|
+
if (remainingPositionals.length > 0) {
|
|
150
|
+
values[rawArg] = remainingPositionals.map((p) => p.value);
|
|
151
|
+
positionalsCount += remainingPositionals.length;
|
|
152
|
+
} else if (schema.required) errors.push(createRequireError(arg, schema));
|
|
153
|
+
} else {
|
|
154
|
+
const positional = positionalTokens[positionalsCount];
|
|
155
|
+
if (positional != null) values[rawArg] = positional.value;
|
|
156
|
+
else errors.push(createRequireError(arg, schema));
|
|
157
|
+
positionalsCount++;
|
|
158
|
+
}
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
145
161
|
if (schema.required) {
|
|
146
162
|
const found = optionTokens.find((token) => {
|
|
147
163
|
return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
|
|
@@ -151,14 +167,6 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
|
|
|
151
167
|
continue;
|
|
152
168
|
}
|
|
153
169
|
}
|
|
154
|
-
if (schema.type === "positional") {
|
|
155
|
-
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
|
|
156
|
-
const positional = positionalTokens[positionalsCount];
|
|
157
|
-
if (positional != null) values[rawArg] = positional.value;
|
|
158
|
-
else errors.push(createRequireError(arg, schema));
|
|
159
|
-
positionalsCount++;
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
170
|
for (let i = 0; i < optionTokens.length; i++) {
|
|
163
171
|
const token = optionTokens[i];
|
|
164
172
|
if (checkTokenName(arg, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
|
package/lib/resolver.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./parser-Cbxholql.js";
|
|
2
|
-
import { ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args,
|
|
3
|
-
export { ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args,
|
|
2
|
+
import { ArgExplicitlyProvided, ArgResolveError$1 as ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs$1 as resolveArgs } from "./resolver-BoS-UnqX.js";
|
|
3
|
+
export { ArgExplicitlyProvided, ArgResolveError, ArgResolveErrorType, ArgSchema, ArgValues, Args, ExtractOptionValue, FilterArgs, FilterPositionalArgs, ResolveArgValues, ResolveArgs, resolveArgs };
|
package/lib/resolver.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "args-tokens",
|
|
3
3
|
"description": "parseArgs tokens compatibility and more high-performance parser",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.22.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -72,33 +72,33 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@eslint/markdown": "^6.6.0",
|
|
75
|
-
"@kazupon/eslint-config": "^0.
|
|
75
|
+
"@kazupon/eslint-config": "^0.33.0",
|
|
76
76
|
"@kazupon/prettier-config": "^0.1.1",
|
|
77
|
-
"@types/node": "^22.
|
|
78
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
77
|
+
"@types/node": "^22.17.0",
|
|
78
|
+
"@typescript/native-preview": "7.0.0-dev.20250731.1",
|
|
79
79
|
"@vitest/eslint-plugin": "^1.3.4",
|
|
80
|
-
"bumpp": "^10.2.
|
|
81
|
-
"deno": "^2.4.
|
|
82
|
-
"eslint": "^9.
|
|
83
|
-
"eslint-config-prettier": "^10.1.
|
|
80
|
+
"bumpp": "^10.2.1",
|
|
81
|
+
"deno": "^2.4.3",
|
|
82
|
+
"eslint": "^9.32.0",
|
|
83
|
+
"eslint-config-prettier": "^10.1.8",
|
|
84
84
|
"eslint-plugin-jsonc": "^2.20.1",
|
|
85
85
|
"eslint-plugin-promise": "^7.2.1",
|
|
86
86
|
"eslint-plugin-regexp": "^2.9.0",
|
|
87
|
-
"eslint-plugin-unicorn": "^
|
|
87
|
+
"eslint-plugin-unicorn": "^60.0.0",
|
|
88
88
|
"eslint-plugin-yml": "^1.18.0",
|
|
89
89
|
"gh-changelogen": "^0.2.8",
|
|
90
90
|
"jsr": "^0.13.5",
|
|
91
91
|
"jsr-exports-lint": "^0.4.1",
|
|
92
|
-
"knip": "^5.
|
|
92
|
+
"knip": "^5.62.0",
|
|
93
93
|
"lint-staged": "^16.1.2",
|
|
94
94
|
"mitata": "^1.0.34",
|
|
95
95
|
"pkg-pr-new": "^0.0.54",
|
|
96
96
|
"prettier": "^3.6.2",
|
|
97
|
-
"tsdown": "^0.
|
|
97
|
+
"tsdown": "^0.13.0",
|
|
98
98
|
"typescript": "^5.8.3",
|
|
99
|
-
"typescript-eslint": "^8.
|
|
99
|
+
"typescript-eslint": "^8.38.0",
|
|
100
100
|
"vitest": "^3.2.4",
|
|
101
|
-
"zod": "^
|
|
101
|
+
"zod": "^4.0.14"
|
|
102
102
|
},
|
|
103
103
|
"prettier": "@kazupon/prettier-config",
|
|
104
104
|
"lint-staged": {
|
|
@@ -124,12 +124,12 @@
|
|
|
124
124
|
"fix": "pnpm run --parallel --color \"/^fix:/\"",
|
|
125
125
|
"fix:eslint": "eslint . --fix",
|
|
126
126
|
"fix:knip": "knip --fix --no-exit-code",
|
|
127
|
-
"fix:prettier": "prettier . --write",
|
|
127
|
+
"fix:prettier": "prettier . --write --experimental-cli",
|
|
128
128
|
"lint": "pnpm run --parallel --color \"/^lint:/\"",
|
|
129
129
|
"lint:eslint": "eslint .",
|
|
130
130
|
"lint:jsr": "jsr publish --config jsr.json --dry-run --allow-dirty",
|
|
131
131
|
"lint:knip": "knip",
|
|
132
|
-
"lint:prettier": "prettier . --check",
|
|
132
|
+
"lint:prettier": "prettier . --check --experimental-cli",
|
|
133
133
|
"release": "bumpp --commit \"release: v%s\" --all --push --tag",
|
|
134
134
|
"test": "vitest run --typecheck",
|
|
135
135
|
"typecheck": "pnpm run --parallel --color \"/^typecheck:/\"",
|