@clerc/parser 1.0.0-beta.24 → 1.0.0-beta.25
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/index.d.ts +2 -5
- package/dist/index.js +6 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,6 @@ declare class MissingRequiredFlagError extends Error {
|
|
|
10
10
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
11
11
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
12
12
|
//#endregion
|
|
13
|
-
//#region ../utils/src/types/index.d.ts
|
|
14
|
-
type MaybeArray<T> = T | T[];
|
|
15
|
-
//#endregion
|
|
16
13
|
//#region src/iterator.d.ts
|
|
17
14
|
declare const KNOWN_FLAG = "known-flag";
|
|
18
15
|
declare const UNKNOWN_FLAG = "unknown-flag";
|
|
@@ -54,8 +51,8 @@ interface BaseFlagOptions<T extends TypeValue = TypeValue> {
|
|
|
54
51
|
* e.g., String, Number, [String], (val) => val.split(',')
|
|
55
52
|
*/
|
|
56
53
|
type: T;
|
|
57
|
-
/**
|
|
58
|
-
|
|
54
|
+
/** Short flag alias (single character). */
|
|
55
|
+
short?: string;
|
|
59
56
|
/** The default value of the flag. */
|
|
60
57
|
default?: unknown;
|
|
61
58
|
/** Whether the flag is required. */
|
package/dist/index.js
CHANGED
|
@@ -122,7 +122,6 @@ function iterateArgs(args, result, shouldProcessAsFlag, isKnownFlag, ignore, cal
|
|
|
122
122
|
//#endregion
|
|
123
123
|
//#region ../utils/src/index.ts
|
|
124
124
|
const looseIsArray = (arr) => Array.isArray(arr);
|
|
125
|
-
const toArray = (a) => Array.isArray(a) ? a : [a];
|
|
126
125
|
/**
|
|
127
126
|
* Converts a dash- or space-separated string to camelCase.
|
|
128
127
|
* Not using regexp for better performance, because this function is used in parser.
|
|
@@ -161,8 +160,12 @@ function buildConfigsAndAliases(delimiters, flags) {
|
|
|
161
160
|
function validateFlagOptions(name, options) {
|
|
162
161
|
const prefix = `Flag "${name}"`;
|
|
163
162
|
if (Array.isArray(options.type) && options.type.length > 1) throw new InvalidSchemaError(`${prefix} has an invalid type array. Only single-element arrays are allowed to denote multiple occurrences.`);
|
|
163
|
+
if (name.length < 2) throw new InvalidSchemaError(`${prefix} name must be at least 2 characters long.`);
|
|
164
164
|
const names = [name];
|
|
165
|
-
if (options.
|
|
165
|
+
if (options.short) {
|
|
166
|
+
if (options.short.length !== 1) throw new InvalidSchemaError(`${prefix} short flag must be exactly 1 character long.`);
|
|
167
|
+
names.push(options.short);
|
|
168
|
+
}
|
|
166
169
|
if (names.some(isNameInvalid)) throw new InvalidSchemaError(`${prefix} contains reserved characters, which are used as delimiters.`);
|
|
167
170
|
}
|
|
168
171
|
for (const [name, config] of Object.entries(flags)) {
|
|
@@ -171,10 +174,7 @@ function buildConfigsAndAliases(delimiters, flags) {
|
|
|
171
174
|
configs.set(name, normalized);
|
|
172
175
|
aliases.set(name, name);
|
|
173
176
|
aliases.set(camelCase(name), name);
|
|
174
|
-
if (normalized.
|
|
175
|
-
const list = Array.isArray(normalized.alias) ? normalized.alias : [normalized.alias];
|
|
176
|
-
for (const a of list) aliases.set(a, name);
|
|
177
|
-
}
|
|
177
|
+
if (normalized.short) aliases.set(normalized.short, name);
|
|
178
178
|
}
|
|
179
179
|
return {
|
|
180
180
|
configs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/parser",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.25",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc parser",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"nopt": "^9.0.0",
|
|
57
57
|
"type-flag": "^4.0.3",
|
|
58
58
|
"yargs-parser": "^22.0.0",
|
|
59
|
-
"@clerc/utils": "1.0.0-beta.
|
|
59
|
+
"@clerc/utils": "1.0.0-beta.25"
|
|
60
60
|
}
|
|
61
61
|
}
|