massarg 2.0.0-pre.1 → 2.0.0-pre.10
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/command.d.ts +49 -19
- package/command.d.ts.map +1 -1
- package/command.js +176 -83
- package/command.js.map +1 -1
- package/error.d.ts +13 -11
- package/error.d.ts.map +1 -1
- package/error.js +1 -1
- package/error.js.map +1 -1
- package/help.d.ts +289 -54
- package/help.d.ts.map +1 -1
- package/help.js +151 -59
- package/help.js.map +1 -1
- package/massarg.d.ts +1 -1
- package/massarg.d.ts.map +1 -1
- package/massarg.js.map +1 -1
- package/option.d.ts +93 -41
- package/option.d.ts.map +1 -1
- package/option.js +59 -56
- package/option.js.map +1 -1
- package/package.json +2 -2
- package/style.d.ts +1 -0
- package/style.d.ts.map +1 -1
- package/style.js +4 -1
- package/style.js.map +1 -1
- package/utils.d.ts +2 -0
- package/utils.d.ts.map +1 -1
- package/utils.js +13 -2
- package/utils.js.map +1 -1
package/option.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { ArgsObject } from './command';
|
|
3
|
+
export declare const OptionConfig: <OptionType, Args extends ArgsObject = ArgsObject>(type: z.ZodType<OptionType, z.ZodTypeDef, OptionType>) => z.ZodObject<{
|
|
3
4
|
/** Name of the option */
|
|
4
5
|
name: z.ZodString;
|
|
5
6
|
/** Description of the option, displayed in the help output */
|
|
@@ -12,7 +13,7 @@ export declare const OptionConfig: <T extends z.ZodType<any, z.ZodTypeDef, any>>
|
|
|
12
13
|
* Parse the value of the option. You can return any type here, or throw an error if the value
|
|
13
14
|
* is invalid.
|
|
14
15
|
*/
|
|
15
|
-
parse: z.ZodOptional<z.
|
|
16
|
+
parse: z.ZodOptional<z.ZodType<Parser<Args, OptionType>, z.ZodTypeDef, Parser<Args, OptionType>>>;
|
|
16
17
|
/**
|
|
17
18
|
* Whether the option is an array.
|
|
18
19
|
*
|
|
@@ -37,107 +38,140 @@ export declare const OptionConfig: <T extends z.ZodType<any, z.ZodTypeDef, any>>
|
|
|
37
38
|
/** Specify a custom name for the output, which will be used when parsing the args. */
|
|
38
39
|
outputName: z.ZodOptional<z.ZodString>;
|
|
39
40
|
}, "strip", z.ZodTypeAny, {
|
|
40
|
-
description: string;
|
|
41
41
|
name: string;
|
|
42
|
+
description: string;
|
|
42
43
|
aliases: string[];
|
|
43
44
|
defaultValue?: any;
|
|
44
|
-
parse?:
|
|
45
|
+
parse?: Parser<Args, OptionType> | undefined;
|
|
45
46
|
array?: boolean | undefined;
|
|
46
47
|
required?: boolean | undefined;
|
|
47
48
|
isDefault?: boolean | undefined;
|
|
48
49
|
hidden?: boolean | undefined;
|
|
49
50
|
outputName?: string | undefined;
|
|
50
51
|
}, {
|
|
51
|
-
description: string;
|
|
52
52
|
name: string;
|
|
53
|
+
description: string;
|
|
53
54
|
aliases: string[];
|
|
54
55
|
defaultValue?: any;
|
|
55
|
-
parse?:
|
|
56
|
+
parse?: Parser<Args, OptionType> | undefined;
|
|
56
57
|
array?: boolean | undefined;
|
|
57
58
|
required?: boolean | undefined;
|
|
58
59
|
isDefault?: boolean | undefined;
|
|
59
60
|
hidden?: boolean | undefined;
|
|
60
61
|
outputName?: string | undefined;
|
|
61
62
|
}>;
|
|
62
|
-
export type OptionConfig<T = unknown> = z.infer<ReturnType<typeof OptionConfig<
|
|
63
|
-
export declare const
|
|
64
|
-
|
|
63
|
+
export type OptionConfig<T = unknown, Args extends ArgsObject = ArgsObject> = z.infer<ReturnType<typeof OptionConfig<T, Args>>>;
|
|
64
|
+
export declare const FlagConfig: z.ZodObject<{
|
|
65
|
+
name: z.ZodString;
|
|
65
66
|
description: z.ZodString;
|
|
67
|
+
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
68
|
+
aliases: z.ZodArray<z.ZodString, "many">;
|
|
69
|
+
array: z.ZodOptional<z.ZodBoolean>;
|
|
70
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
outputName: z.ZodOptional<z.ZodString>;
|
|
73
|
+
negatable: z.ZodOptional<z.ZodBoolean>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
name: string;
|
|
76
|
+
description: string;
|
|
77
|
+
aliases: string[];
|
|
78
|
+
defaultValue?: any;
|
|
79
|
+
array?: boolean | undefined;
|
|
80
|
+
required?: boolean | undefined;
|
|
81
|
+
hidden?: boolean | undefined;
|
|
82
|
+
outputName?: string | undefined;
|
|
83
|
+
negatable?: boolean | undefined;
|
|
84
|
+
}, {
|
|
85
|
+
name: string;
|
|
86
|
+
description: string;
|
|
87
|
+
aliases: string[];
|
|
88
|
+
defaultValue?: any;
|
|
89
|
+
array?: boolean | undefined;
|
|
90
|
+
required?: boolean | undefined;
|
|
91
|
+
hidden?: boolean | undefined;
|
|
92
|
+
outputName?: string | undefined;
|
|
93
|
+
negatable?: boolean | undefined;
|
|
94
|
+
}>;
|
|
95
|
+
export type FlagConfig = z.infer<typeof FlagConfig>;
|
|
96
|
+
export type Parser<Args extends ArgsObject = ArgsObject, OptionType extends any = any> = (x: string, y: Args) => OptionType;
|
|
97
|
+
export declare const TypedOptionConfig: <OptionType, Args extends ArgsObject = ArgsObject>(type: z.ZodType<OptionType, z.ZodTypeDef, OptionType>) => z.ZodObject<{
|
|
66
98
|
name: z.ZodString;
|
|
99
|
+
description: z.ZodString;
|
|
67
100
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
68
101
|
aliases: z.ZodArray<z.ZodString, "many">;
|
|
69
|
-
|
|
102
|
+
array: z.ZodOptional<z.ZodBoolean>;
|
|
70
103
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
71
104
|
isDefault: z.ZodOptional<z.ZodBoolean>;
|
|
72
105
|
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
73
106
|
outputName: z.ZodOptional<z.ZodString>;
|
|
107
|
+
parse: z.ZodOptional<z.ZodType<Parser<Args, OptionType>, z.ZodTypeDef, Parser<Args, OptionType>>>;
|
|
74
108
|
type: z.ZodOptional<z.ZodEnum<["number"]>>;
|
|
75
109
|
}, "strip", z.ZodTypeAny, {
|
|
76
|
-
description: string;
|
|
77
110
|
name: string;
|
|
111
|
+
description: string;
|
|
78
112
|
aliases: string[];
|
|
79
|
-
array?: boolean | undefined;
|
|
80
113
|
defaultValue?: any;
|
|
81
|
-
|
|
114
|
+
array?: boolean | undefined;
|
|
82
115
|
required?: boolean | undefined;
|
|
83
116
|
isDefault?: boolean | undefined;
|
|
84
117
|
hidden?: boolean | undefined;
|
|
85
118
|
outputName?: string | undefined;
|
|
119
|
+
parse?: Parser<Args, OptionType> | undefined;
|
|
86
120
|
type?: "number" | undefined;
|
|
87
121
|
}, {
|
|
88
|
-
description: string;
|
|
89
122
|
name: string;
|
|
123
|
+
description: string;
|
|
90
124
|
aliases: string[];
|
|
91
|
-
array?: boolean | undefined;
|
|
92
125
|
defaultValue?: any;
|
|
93
|
-
|
|
126
|
+
array?: boolean | undefined;
|
|
94
127
|
required?: boolean | undefined;
|
|
95
128
|
isDefault?: boolean | undefined;
|
|
96
129
|
hidden?: boolean | undefined;
|
|
97
130
|
outputName?: string | undefined;
|
|
131
|
+
parse?: Parser<Args, OptionType> | undefined;
|
|
98
132
|
type?: "number" | undefined;
|
|
99
133
|
}>;
|
|
100
|
-
export type TypedOptionConfig<T =
|
|
134
|
+
export type TypedOptionConfig<T, A extends ArgsObject = ArgsObject> = z.infer<ReturnType<typeof TypedOptionConfig<T, A>>>;
|
|
101
135
|
/**
|
|
102
136
|
* @see OptionConfig
|
|
103
137
|
* @see ArrayOptionConfig
|
|
104
138
|
*/
|
|
105
|
-
export declare const ArrayOptionConfig: <T extends z.ZodType<
|
|
139
|
+
export declare const ArrayOptionConfig: <T, A extends ArgsObject = ArgsObject>(type: z.ZodType<T, z.ZodTypeDef, T>) => z.ZodObject<{
|
|
106
140
|
type: z.ZodOptional<z.ZodEnum<["number"]>>;
|
|
107
|
-
array: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
-
description: z.ZodString;
|
|
109
141
|
name: z.ZodString;
|
|
142
|
+
description: z.ZodString;
|
|
110
143
|
aliases: z.ZodArray<z.ZodString, "many">;
|
|
111
|
-
|
|
144
|
+
array: z.ZodOptional<z.ZodBoolean>;
|
|
112
145
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
113
146
|
isDefault: z.ZodOptional<z.ZodBoolean>;
|
|
114
147
|
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
115
148
|
outputName: z.ZodOptional<z.ZodString>;
|
|
116
|
-
|
|
149
|
+
parse: z.ZodOptional<z.ZodType<Parser<A, T[]>, z.ZodTypeDef, Parser<A, T[]>>>;
|
|
150
|
+
defaultValue: z.ZodOptional<z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">>;
|
|
117
151
|
}, "strip", z.ZodTypeAny, {
|
|
118
|
-
description: string;
|
|
119
152
|
name: string;
|
|
153
|
+
description: string;
|
|
120
154
|
aliases: string[];
|
|
121
155
|
type?: "number" | undefined;
|
|
122
156
|
array?: boolean | undefined;
|
|
123
|
-
parse?: ((args_0: string, ...args_1: unknown[]) => T["_output"][]) | undefined;
|
|
124
157
|
required?: boolean | undefined;
|
|
125
158
|
isDefault?: boolean | undefined;
|
|
126
159
|
hidden?: boolean | undefined;
|
|
127
160
|
outputName?: string | undefined;
|
|
128
|
-
|
|
161
|
+
parse?: Parser<A, T[]> | undefined;
|
|
162
|
+
defaultValue?: T[] | undefined;
|
|
129
163
|
}, {
|
|
130
|
-
description: string;
|
|
131
164
|
name: string;
|
|
165
|
+
description: string;
|
|
132
166
|
aliases: string[];
|
|
133
167
|
type?: "number" | undefined;
|
|
134
168
|
array?: boolean | undefined;
|
|
135
|
-
parse?: ((args_0: string, ...args_1: unknown[]) => T["_input"][]) | undefined;
|
|
136
169
|
required?: boolean | undefined;
|
|
137
170
|
isDefault?: boolean | undefined;
|
|
138
171
|
hidden?: boolean | undefined;
|
|
139
172
|
outputName?: string | undefined;
|
|
140
|
-
|
|
173
|
+
parse?: Parser<A, T[]> | undefined;
|
|
174
|
+
defaultValue?: T[] | undefined;
|
|
141
175
|
}>;
|
|
142
176
|
/**
|
|
143
177
|
* An option that can be passed to a command.
|
|
@@ -145,6 +179,16 @@ export declare const ArrayOptionConfig: <T extends z.ZodType<any, z.ZodTypeDef,
|
|
|
145
179
|
* This type represents an array option, which can be specified multiple times.
|
|
146
180
|
*/
|
|
147
181
|
export type ArrayOptionConfig<T = unknown> = z.infer<ReturnType<typeof ArrayOptionConfig<z.ZodType<T>>>>;
|
|
182
|
+
export declare const OPT_FULL_PREFIX = "--";
|
|
183
|
+
export declare const OPT_SHORT_PREFIX = "-";
|
|
184
|
+
export declare const NEGATE_FULL_PREFIX = "--no-";
|
|
185
|
+
export declare const NEGATE_SHORT_PREFIX = "^";
|
|
186
|
+
export type Prefixes = {
|
|
187
|
+
optionPrefix: string;
|
|
188
|
+
aliasPrefix: string;
|
|
189
|
+
negateFlagPrefix: string;
|
|
190
|
+
negateAliasPrefix: string;
|
|
191
|
+
};
|
|
148
192
|
/** @internal */
|
|
149
193
|
export type ArgvValue<T> = {
|
|
150
194
|
argv: string[];
|
|
@@ -173,22 +217,29 @@ export type ArgvValue<T> = {
|
|
|
173
217
|
* })
|
|
174
218
|
* ```
|
|
175
219
|
*/
|
|
176
|
-
export declare class MassargOption<
|
|
220
|
+
export declare class MassargOption<OptionType extends any = unknown, Args extends ArgsObject = ArgsObject> implements OptionConfig<OptionType, Args> {
|
|
177
221
|
name: string;
|
|
178
222
|
description: string;
|
|
179
|
-
defaultValue?:
|
|
223
|
+
defaultValue?: OptionType;
|
|
180
224
|
aliases: string[];
|
|
181
|
-
parse:
|
|
225
|
+
parse: Parser<Args, OptionType>;
|
|
182
226
|
isArray: boolean;
|
|
227
|
+
isRequired: boolean;
|
|
183
228
|
isDefault: boolean;
|
|
184
229
|
outputName?: string;
|
|
185
|
-
constructor(options: OptionConfig<
|
|
186
|
-
static fromTypedConfig<T = unknown>(config: TypedOptionConfig<T>): MassargOption<T>;
|
|
187
|
-
|
|
230
|
+
constructor(options: OptionConfig<OptionType, Args>);
|
|
231
|
+
static fromTypedConfig<T = unknown, A extends ArgsObject = ArgsObject>(config: TypedOptionConfig<T, A>): MassargOption<T>;
|
|
232
|
+
getOutputName(): string;
|
|
233
|
+
parseDetails(argv: string[], options: ArgsObject, prefixes: Prefixes): ArgvValue<OptionType>;
|
|
188
234
|
helpString(): string;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
235
|
+
/** Returns true if the flag (including any prefixes) matches the name or aliases */
|
|
236
|
+
isMatch(arg: string, prefixes: Prefixes): boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Returns the name of the flag, removing any prefixes. It is discriminate of if the option
|
|
239
|
+
* exists, as it is a static method; it only returns the name of the flag if it matches the
|
|
240
|
+
* prefixes format.
|
|
241
|
+
*/
|
|
242
|
+
static findNameInArg(arg: string, prefixes: Prefixes): string;
|
|
192
243
|
}
|
|
193
244
|
/**
|
|
194
245
|
* An option that can be passed to a command.
|
|
@@ -208,7 +259,7 @@ export declare class MassargOption<T = unknown> {
|
|
|
208
259
|
*/
|
|
209
260
|
export declare class MassargNumber extends MassargOption<number> {
|
|
210
261
|
constructor(options: Omit<OptionConfig<number>, 'parse'>);
|
|
211
|
-
|
|
262
|
+
parseDetails(argv: string[], options: ArgsObject, prefixes: Prefixes): ArgvValue<number>;
|
|
212
263
|
}
|
|
213
264
|
/**
|
|
214
265
|
* An option that can be passed to a command.
|
|
@@ -219,7 +270,7 @@ export declare class MassargNumber extends MassargOption<number> {
|
|
|
219
270
|
*
|
|
220
271
|
* A flag can be negated by prefixing it with `no-`. For example, `--no-verbose`,
|
|
221
272
|
* or by prefixing the alias with `^` instead of `-`. This is configurable via the command's
|
|
222
|
-
* configuration.
|
|
273
|
+
* configuration. To turn this behavior on, set `negatable: true` in the flag's configuration.
|
|
223
274
|
*
|
|
224
275
|
* @example
|
|
225
276
|
* ```ts
|
|
@@ -232,8 +283,9 @@ export declare class MassargNumber extends MassargOption<number> {
|
|
|
232
283
|
* ```
|
|
233
284
|
*/
|
|
234
285
|
export declare class MassargFlag extends MassargOption<boolean> {
|
|
235
|
-
|
|
236
|
-
|
|
286
|
+
negatable: boolean;
|
|
287
|
+
constructor(options: FlagConfig);
|
|
288
|
+
parseDetails(argv: string[], _options: ArgsObject, prefixes: Prefixes): ArgvValue<boolean>;
|
|
237
289
|
}
|
|
238
290
|
export declare class MassargHelpFlag extends MassargFlag {
|
|
239
291
|
constructor(config?: Partial<Omit<OptionConfig<boolean>, 'parse'>>);
|
package/option.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,eAAO,MAAM,YAAY;IAIrB,yBAAyB;;IAEzB,8DAA8D;;IAE9D,kCAAkC;;IAElC,oFAAoF;;IAEpF;;;OAGG;;IAIH;;;;;;OAMG;;IAEH;;OAEG;;IAEH;;;;;OAKG;;IAEH,yFAAyF;;IAEzF,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;EAEtF,CAAA;AACJ,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,SAAS,UAAU,GAAG,UAAU,IAAI,CAAC,CAAC,KAAK,CACnF,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CACzC,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC;gBAC1C,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAOxD,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC;CAwBzF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,WAAY,SAAQ,aAAa,CAAC,OAAO,CAAC;IACrD,SAAS,EAAE,OAAO,CAAA;gBAEN,OAAO,EAAE,UAAU;IAQ/B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;CAsC3F;AAED,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAM;CAQvE"}
|
package/option.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MassargHelpFlag = exports.MassargFlag = exports.MassargNumber = exports.MassargOption = exports.ArrayOptionConfig = exports.TypedOptionConfig = exports.OptionConfig = void 0;
|
|
3
|
+
exports.MassargHelpFlag = exports.MassargFlag = exports.MassargNumber = exports.MassargOption = exports.NEGATE_SHORT_PREFIX = exports.NEGATE_FULL_PREFIX = exports.OPT_SHORT_PREFIX = exports.OPT_FULL_PREFIX = exports.ArrayOptionConfig = exports.TypedOptionConfig = exports.FlagConfig = exports.OptionConfig = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
@@ -17,7 +17,7 @@ const OptionConfig = (type) => zod_1.z.object({
|
|
|
17
17
|
* Parse the value of the option. You can return any type here, or throw an error if the value
|
|
18
18
|
* is invalid.
|
|
19
19
|
*/
|
|
20
|
-
parse: zod_1.z.function().args(zod_1.z.string()).returns(type).optional(),
|
|
20
|
+
parse: zod_1.z.function().args(zod_1.z.string(), zod_1.z.any()).returns(type).optional(),
|
|
21
21
|
/**
|
|
22
22
|
* Whether the option is an array.
|
|
23
23
|
*
|
|
@@ -43,6 +43,12 @@ const OptionConfig = (type) => zod_1.z.object({
|
|
|
43
43
|
outputName: zod_1.z.string().optional(),
|
|
44
44
|
});
|
|
45
45
|
exports.OptionConfig = OptionConfig;
|
|
46
|
+
exports.FlagConfig = (0, exports.OptionConfig)(zod_1.z.any())
|
|
47
|
+
.omit({ parse: true, isDefault: true })
|
|
48
|
+
.merge(zod_1.z.object({
|
|
49
|
+
/** Whether the flag can be negated, e.g. `--no-verbose` */
|
|
50
|
+
negatable: zod_1.z.boolean().optional(),
|
|
51
|
+
}));
|
|
46
52
|
const TypedOptionConfig = (type) => (0, exports.OptionConfig)(type).merge(zod_1.z.object({
|
|
47
53
|
type: zod_1.z.enum(['number']).optional(),
|
|
48
54
|
}));
|
|
@@ -58,10 +64,10 @@ zod_1.z.object({
|
|
|
58
64
|
}));
|
|
59
65
|
exports.ArrayOptionConfig = ArrayOptionConfig;
|
|
60
66
|
// TODO turn to options
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
exports.OPT_FULL_PREFIX = '--';
|
|
68
|
+
exports.OPT_SHORT_PREFIX = '-';
|
|
69
|
+
exports.NEGATE_FULL_PREFIX = '--no-';
|
|
70
|
+
exports.NEGATE_SHORT_PREFIX = '^';
|
|
65
71
|
/**
|
|
66
72
|
* An option that can be passed to a command.
|
|
67
73
|
*
|
|
@@ -94,6 +100,7 @@ class MassargOption {
|
|
|
94
100
|
this.parse = options.parse ?? ((x) => x);
|
|
95
101
|
this.isArray = options.array ?? false;
|
|
96
102
|
this.isDefault = options.isDefault ?? false;
|
|
103
|
+
this.isRequired = options.required ?? false;
|
|
97
104
|
this.outputName = options.outputName;
|
|
98
105
|
}
|
|
99
106
|
static fromTypedConfig(config) {
|
|
@@ -103,11 +110,13 @@ class MassargOption {
|
|
|
103
110
|
}
|
|
104
111
|
return new MassargOption(config);
|
|
105
112
|
}
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
getOutputName() {
|
|
114
|
+
return this.outputName || (0, utils_1.toCamelCase)(this.name);
|
|
115
|
+
}
|
|
116
|
+
parseDetails(argv, options, prefixes) {
|
|
108
117
|
let input = '';
|
|
109
118
|
try {
|
|
110
|
-
if (!this.
|
|
119
|
+
if (!this.isMatch(argv[0], prefixes)) {
|
|
111
120
|
throw new error_1.ParseError({
|
|
112
121
|
path: [this.name],
|
|
113
122
|
code: 'invalid_option',
|
|
@@ -117,8 +126,8 @@ class MassargOption {
|
|
|
117
126
|
}
|
|
118
127
|
argv.shift();
|
|
119
128
|
input = argv.shift();
|
|
120
|
-
const value = this.parse(input);
|
|
121
|
-
return { key: this.
|
|
129
|
+
const value = this.parse(input, options);
|
|
130
|
+
return { key: this.getOutputName(), value, argv };
|
|
122
131
|
}
|
|
123
132
|
catch (e) {
|
|
124
133
|
if ((0, error_1.isZodError)(e)) {
|
|
@@ -136,48 +145,32 @@ class MassargOption {
|
|
|
136
145
|
const aliases = this.aliases.length ? `|${this.aliases.join('|-')}` : '';
|
|
137
146
|
return `--${this.name}${aliases} ${this.description}`;
|
|
138
147
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
/** Returns true if the flag (including any prefixes) matches the name or aliases */
|
|
149
|
+
isMatch(arg, prefixes) {
|
|
150
|
+
const name = MassargOption.findNameInArg(arg, prefixes);
|
|
151
|
+
return name === this.name || this.aliases.includes(name);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the name of the flag, removing any prefixes. It is discriminate of if the option
|
|
155
|
+
* exists, as it is a static method; it only returns the name of the flag if it matches the
|
|
156
|
+
* prefixes format.
|
|
157
|
+
*/
|
|
158
|
+
static findNameInArg(arg, prefixes) {
|
|
159
|
+
const { optionPrefix, aliasPrefix, negateFlagPrefix, negateAliasPrefix } = prefixes;
|
|
160
|
+
// negate full prefix
|
|
161
|
+
if (arg.startsWith(negateFlagPrefix)) {
|
|
162
|
+
return arg.slice(negateFlagPrefix.length);
|
|
149
163
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return this.aliases.includes(arg.slice(OPT_SHORT_PREFIX.length));
|
|
164
|
+
if (arg.startsWith(optionPrefix)) {
|
|
165
|
+
return arg.slice(optionPrefix.length);
|
|
153
166
|
}
|
|
154
167
|
// negate short prefix
|
|
155
|
-
if (arg.startsWith(
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
// no prefix
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
_isOption(arg) {
|
|
162
|
-
return (arg.startsWith(OPT_FULL_PREFIX) ||
|
|
163
|
-
arg.startsWith(OPT_SHORT_PREFIX) ||
|
|
164
|
-
arg.startsWith(NEGATE_SHORT_PREFIX));
|
|
165
|
-
}
|
|
166
|
-
static getName(arg) {
|
|
167
|
-
if (arg.startsWith(OPT_FULL_PREFIX)) {
|
|
168
|
-
// negate full prefix
|
|
169
|
-
if (arg.startsWith(`--${NEGATE_FULL_PREFIX}`)) {
|
|
170
|
-
return arg.slice(`--${NEGATE_FULL_PREFIX}`.length);
|
|
171
|
-
}
|
|
172
|
-
return arg.slice(OPT_FULL_PREFIX.length);
|
|
168
|
+
if (arg.startsWith(negateAliasPrefix)) {
|
|
169
|
+
return arg.slice(negateAliasPrefix.length);
|
|
173
170
|
}
|
|
174
171
|
// short prefix
|
|
175
|
-
if (arg.startsWith(
|
|
176
|
-
return arg.slice(
|
|
177
|
-
}
|
|
178
|
-
// negate short prefix
|
|
179
|
-
if (arg.startsWith(NEGATE_SHORT_PREFIX)) {
|
|
180
|
-
return arg.slice(NEGATE_SHORT_PREFIX.length);
|
|
172
|
+
if (arg.startsWith(aliasPrefix) || arg.startsWith(negateAliasPrefix)) {
|
|
173
|
+
return arg.slice(aliasPrefix.length);
|
|
181
174
|
}
|
|
182
175
|
return '<blank>';
|
|
183
176
|
}
|
|
@@ -206,9 +199,9 @@ class MassargNumber extends MassargOption {
|
|
|
206
199
|
parse: (value) => Number(value),
|
|
207
200
|
});
|
|
208
201
|
}
|
|
209
|
-
|
|
202
|
+
parseDetails(argv, options, prefixes) {
|
|
210
203
|
try {
|
|
211
|
-
const { argv: _argv, value } = super.
|
|
204
|
+
const { argv: _argv, value } = super.parseDetails(argv, options, prefixes);
|
|
212
205
|
if (isNaN(value)) {
|
|
213
206
|
throw new error_1.ParseError({
|
|
214
207
|
path: [this.name],
|
|
@@ -242,7 +235,7 @@ exports.MassargNumber = MassargNumber;
|
|
|
242
235
|
*
|
|
243
236
|
* A flag can be negated by prefixing it with `no-`. For example, `--no-verbose`,
|
|
244
237
|
* or by prefixing the alias with `^` instead of `-`. This is configurable via the command's
|
|
245
|
-
* configuration.
|
|
238
|
+
* configuration. To turn this behavior on, set `negatable: true` in the flag's configuration.
|
|
246
239
|
*
|
|
247
240
|
* @example
|
|
248
241
|
* ```ts
|
|
@@ -260,11 +253,21 @@ class MassargFlag extends MassargOption {
|
|
|
260
253
|
...options,
|
|
261
254
|
parse: () => true,
|
|
262
255
|
});
|
|
256
|
+
this.negatable = options.negatable ?? false;
|
|
263
257
|
}
|
|
264
|
-
|
|
258
|
+
parseDetails(argv, _options, prefixes) {
|
|
265
259
|
try {
|
|
266
|
-
const isNegation = argv[0]?.startsWith(
|
|
267
|
-
|
|
260
|
+
const isNegation = argv[0]?.startsWith(prefixes.negateAliasPrefix) ||
|
|
261
|
+
argv[0]?.startsWith(prefixes.negateFlagPrefix);
|
|
262
|
+
if (!this.negatable && isNegation) {
|
|
263
|
+
throw new error_1.ParseError({
|
|
264
|
+
path: [this.name],
|
|
265
|
+
code: 'invalid_option',
|
|
266
|
+
message: `Option ${this.name} cannot be negated`,
|
|
267
|
+
received: JSON.stringify(argv[0]),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (!this.isMatch(argv[0], prefixes)) {
|
|
268
271
|
throw new error_1.ParseError({
|
|
269
272
|
path: [this.name],
|
|
270
273
|
code: 'invalid_option',
|
|
@@ -274,9 +277,9 @@ class MassargFlag extends MassargOption {
|
|
|
274
277
|
}
|
|
275
278
|
argv.shift();
|
|
276
279
|
if (isNegation) {
|
|
277
|
-
return { key: this.
|
|
280
|
+
return { key: this.getOutputName(), value: false, argv };
|
|
278
281
|
}
|
|
279
|
-
return { key: this.
|
|
282
|
+
return { key: this.getOutputName(), value: true, argv };
|
|
280
283
|
}
|
|
281
284
|
catch (e) {
|
|
282
285
|
if ((0, error_1.isZodError)(e)) {
|
package/option.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option.js","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,mCAAgD;AAChD,mCAAqC;
|
|
1
|
+
{"version":3,"file":"option.js","sourceRoot":"","sources":["../src/option.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,mCAAgD;AAChD,mCAAqC;AAG9B,MAAM,YAAY,GAAG,CAC1B,IAA2B,EAC3B,EAAE,CACF,OAAC,CAAC,MAAM,CAAC;IACP,yBAAyB;IACzB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,8DAA8D;IAC9D,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,kCAAkC;IAClC,YAAY,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,oFAAoF;IACpF,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;IAC3B;;;OAGG;IACH,KAAK,EAAE,OAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,OAAC,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AK,CAAC;YACJ,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,wBAAwB;YACrC,OAAO,EAAE,CAAC,GAAG,CAAC;YACd,GAAG,MAAM;SACV,CAAC,CAAA;IACJ,CAAC;CACF;AATD,0CASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "massarg",
|
|
3
|
-
"version": "2.0.0-pre.
|
|
3
|
+
"version": "2.0.0-pre.10",
|
|
4
4
|
"description": "Flexible, powerful, and simple command/argument parser for CLI applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shell",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dev": "tsc --watch",
|
|
20
20
|
"cmd": "ts-node src/sample.ts",
|
|
21
21
|
"test": "jest",
|
|
22
|
-
"doc": "typedoc
|
|
22
|
+
"doc": "typedoc",
|
|
23
23
|
"deploy-doc": "pnpm doc && gh-pages -d docs",
|
|
24
24
|
"semantic-release": "semantic-release"
|
|
25
25
|
},
|
package/style.d.ts
CHANGED
package/style.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE3C,eAAO,MAAM,UAAU;;;;;CAKtB,CAAA;AAED,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;CAiBtB,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;EAKtB,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAErD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,WAAgB,GAAG,MAAM,CAOtE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|
package/style.js
CHANGED
|
@@ -3,9 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.stripStyle = exports.format = exports.StringStyle = exports.ansiColors = exports.ansiStyles = void 0;
|
|
6
|
+
exports.stripStyle = exports.format = exports.StringStyle = exports.ansiColors = exports.ansiStyles = exports.indent = exports.strConcat = void 0;
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
|
8
8
|
const utils_1 = require("./utils");
|
|
9
|
+
var utils_2 = require("./utils");
|
|
10
|
+
Object.defineProperty(exports, "strConcat", { enumerable: true, get: function () { return utils_2.strConcat; } });
|
|
11
|
+
Object.defineProperty(exports, "indent", { enumerable: true, get: function () { return utils_2.indent; } });
|
|
9
12
|
exports.ansiStyles = {
|
|
10
13
|
reset: '\x1b[0m',
|
|
11
14
|
bold: '\x1b[1m',
|
package/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,mCAA4C;
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,mCAA4C;AAC5C,iCAA2C;AAAlC,kGAAA,SAAS,OAAA;AAAE,+FAAA,MAAM,OAAA;AAEb,QAAA,UAAU,GAAG;IACxB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,SAAS,EAAE,SAAS;IACpB,KAAK,EAAE,UAAU;CAClB,CAAA;AAEY,QAAA,UAAU,GAAG;IACxB,GA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,CAAC,kBAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/C,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,EAAE,CAAA;AACvE,CAAC;AAPD,wBAOC;AAED,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;AAC3C,CAAC;AAFD,gCAEC"}
|
package/utils.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare function indent(str: Parseable | Parseable[], indent?: number): s
|
|
|
23
23
|
export declare function zodEnumFromObjKeys<K extends string>(obj: Record<K, any>): z.ZodEnum<[K, ...K[]]>;
|
|
24
24
|
/** @internal */
|
|
25
25
|
export declare function deepMerge<T1, T2>(obj1: T1, obj2: T2): NonNullable<T1> & NonNullable<T2>;
|
|
26
|
+
export declare function capitalize(str: string): string;
|
|
26
27
|
/**
|
|
27
28
|
* Splits a name into words, using camelCase, PascalCase, snake_case, and kebab-case or
|
|
28
29
|
* regular spaced strings.
|
|
@@ -30,5 +31,6 @@ export declare function deepMerge<T1, T2>(obj1: T1, obj2: T2): NonNullable<T1> &
|
|
|
30
31
|
export declare function splitWords(str: string): string[];
|
|
31
32
|
export declare function toCamelCase(str: string): string;
|
|
32
33
|
export declare function toPascalCase(str: string): string;
|
|
34
|
+
export declare function getErrorMessage(err: unknown): string;
|
|
33
35
|
export {};
|
|
34
36
|
//# sourceMappingURL=utils.d.ts.map
|
package/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAGnB,gBAAgB;AAChB,wBAAg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