massarg 2.0.0-pre.8 → 2.0.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/README.md +58 -193
- package/command.d.ts +25 -25
- package/command.d.ts.map +1 -1
- package/command.js +98 -83
- package/command.js.map +1 -1
- package/error.js.map +1 -1
- package/example.js.map +1 -1
- package/help.d.ts +139 -29
- package/help.d.ts.map +1 -1
- package/help.js +70 -49
- package/help.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/massarg.d.ts +14 -2
- package/massarg.d.ts.map +1 -1
- package/massarg.js +12 -0
- package/massarg.js.map +1 -1
- package/option.d.ts +65 -21
- package/option.d.ts.map +1 -1
- package/option.js +69 -37
- package/option.js.map +1 -1
- package/package.json +17 -13
- package/style.js +3 -3
- package/style.js.map +1 -1
- package/utils.d.ts +5 -5
- package/utils.d.ts.map +1 -1
- package/utils.js +8 -8
- package/utils.js.map +1 -1
package/index.js
CHANGED
|
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const massarg_1 = require("./massarg");
|
|
17
18
|
__exportStar(require("./massarg"), exports);
|
|
19
|
+
exports.default = massarg_1.massarg;
|
|
18
20
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAmC;AAEnC,4CAAyB;AAEzB,kBAAe,iBAAO,CAAA"}
|
package/massarg.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { ArgsObject, CommandConfig, MassargCommand } from './command';
|
|
2
|
-
|
|
2
|
+
/** A minimal command config that can be used to create a top-level command. */
|
|
3
|
+
export type MinimalCommandConfig<Args extends ArgsObject = ArgsObject> = Omit<CommandConfig<Args>, 'aliases' | 'run'> & Partial<Pick<CommandConfig<Args>, 'aliases' | 'run'>>;
|
|
4
|
+
/**
|
|
5
|
+
* This class behaves similarly to {@link MassargCommand}, but it accepts only params that are relevant
|
|
6
|
+
* to the top-level command.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link massarg}
|
|
9
|
+
* @see {@link MassargCommand}
|
|
10
|
+
*/
|
|
3
11
|
export declare class Massarg<Args extends ArgsObject = ArgsObject> extends MassargCommand<Args> {
|
|
4
12
|
constructor(options: MinimalCommandConfig<Args>);
|
|
5
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new top-level command.
|
|
16
|
+
* @see {@link MassargCommand}
|
|
17
|
+
* @see {@link Massarg}
|
|
18
|
+
*/
|
|
6
19
|
export declare function massarg<Args extends ArgsObject = ArgsObject>(options: MinimalCommandConfig<Args>): MassargCommand<Args>;
|
|
7
|
-
export {};
|
|
8
20
|
//# sourceMappingURL=massarg.d.ts.map
|
package/massarg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"massarg.d.ts","sourceRoot":"","sources":["../src/massarg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAErE,
|
|
1
|
+
{"version":3,"file":"massarg.d.ts","sourceRoot":"","sources":["../src/massarg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAErE,+EAA+E;AAC/E,MAAM,MAAM,oBAAoB,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,IAAI,IAAI,CAC3E,aAAa,CAAC,IAAI,CAAC,EACnB,SAAS,GAAG,KAAK,CAClB,GACC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,CAAC,CAAA;AAEvD;;;;;;GAMG;AACH,qBAAa,OAAO,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,cAAc,CAAC,IAAI,CAAC;gBACzE,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC;CAWhD;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,EAC1D,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAClC,cAAc,CAAC,IAAI,CAAC,CAEtB"}
|
package/massarg.js
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.massarg = exports.Massarg = void 0;
|
|
4
4
|
const command_1 = require("./command");
|
|
5
|
+
/**
|
|
6
|
+
* This class behaves similarly to {@link MassargCommand}, but it accepts only params that are relevant
|
|
7
|
+
* to the top-level command.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link massarg}
|
|
10
|
+
* @see {@link MassargCommand}
|
|
11
|
+
*/
|
|
5
12
|
class Massarg extends command_1.MassargCommand {
|
|
6
13
|
constructor(options) {
|
|
7
14
|
// TODO consider re-using name and description for general help, and pass them to super
|
|
@@ -16,6 +23,11 @@ class Massarg extends command_1.MassargCommand {
|
|
|
16
23
|
}
|
|
17
24
|
}
|
|
18
25
|
exports.Massarg = Massarg;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new top-level command.
|
|
28
|
+
* @see {@link MassargCommand}
|
|
29
|
+
* @see {@link Massarg}
|
|
30
|
+
*/
|
|
19
31
|
function massarg(options) {
|
|
20
32
|
return new Massarg(options);
|
|
21
33
|
}
|
package/massarg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"massarg.js","sourceRoot":"","sources":["../src/massarg.ts"],"names":[],"mappings":";;;AAAA,uCAAqE;
|
|
1
|
+
{"version":3,"file":"massarg.js","sourceRoot":"","sources":["../src/massarg.ts"],"names":[],"mappings":";;;AAAA,uCAAqE;AASrE;;;;;;GAMG;AACH,MAAa,OAA8C,SAAQ,wBAAoB;IACrF,YAAY,OAAmC;QAC7C,uFAAuF;QACvF,KAAK,CAAC;YACJ,OAAO,EAAE,EAAE;YACX,GAAG,EAAE,GAAG,EAAE;gBACR,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAA;gBAC9B,8CAA8C;YAChD,CAAC;YACD,GAAG,OAAO;SACX,CAAC,CAAA;IACJ,CAAC;CACF;AAZD,0BAYC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CACrB,OAAmC;IAEnC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;AAC7B,CAAC;AAJD,0BAIC"}
|
package/option.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ArgsObject } from './command';
|
|
3
|
-
export declare const OptionConfig: <OptionType, Args extends
|
|
3
|
+
export declare const OptionConfig: <OptionType, Args extends ArgsObject = ArgsObject>(type: z.ZodType<OptionType, z.ZodTypeDef, OptionType>) => z.ZodObject<{
|
|
4
4
|
/** Name of the option */
|
|
5
5
|
name: z.ZodString;
|
|
6
6
|
/** Description of the option, displayed in the help output */
|
|
@@ -61,6 +61,9 @@ export declare const OptionConfig: <OptionType, Args extends object = object>(ty
|
|
|
61
61
|
outputName?: string | undefined;
|
|
62
62
|
}>;
|
|
63
63
|
export type OptionConfig<T = unknown, Args extends ArgsObject = ArgsObject> = z.infer<ReturnType<typeof OptionConfig<T, Args>>>;
|
|
64
|
+
/**
|
|
65
|
+
* Configuration for a flag (boolean argument) that can be passed to a command.
|
|
66
|
+
*/
|
|
64
67
|
export declare const FlagConfig: z.ZodObject<{
|
|
65
68
|
name: z.ZodString;
|
|
66
69
|
description: z.ZodString;
|
|
@@ -71,6 +74,8 @@ export declare const FlagConfig: z.ZodObject<{
|
|
|
71
74
|
hidden: z.ZodOptional<z.ZodBoolean>;
|
|
72
75
|
outputName: z.ZodOptional<z.ZodString>;
|
|
73
76
|
negatable: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
negationName: z.ZodOptional<z.ZodString>;
|
|
78
|
+
negationAliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
74
79
|
}, "strip", z.ZodTypeAny, {
|
|
75
80
|
name: string;
|
|
76
81
|
description: string;
|
|
@@ -81,6 +86,8 @@ export declare const FlagConfig: z.ZodObject<{
|
|
|
81
86
|
hidden?: boolean | undefined;
|
|
82
87
|
outputName?: string | undefined;
|
|
83
88
|
negatable?: boolean | undefined;
|
|
89
|
+
negationName?: string | undefined;
|
|
90
|
+
negationAliases?: string[] | undefined;
|
|
84
91
|
}, {
|
|
85
92
|
name: string;
|
|
86
93
|
description: string;
|
|
@@ -91,10 +98,16 @@ export declare const FlagConfig: z.ZodObject<{
|
|
|
91
98
|
hidden?: boolean | undefined;
|
|
92
99
|
outputName?: string | undefined;
|
|
93
100
|
negatable?: boolean | undefined;
|
|
101
|
+
negationName?: string | undefined;
|
|
102
|
+
negationAliases?: string[] | undefined;
|
|
94
103
|
}>;
|
|
95
104
|
export type FlagConfig = z.infer<typeof FlagConfig>;
|
|
105
|
+
/**
|
|
106
|
+
* A function that parses an option value.
|
|
107
|
+
*/
|
|
96
108
|
export type Parser<Args extends ArgsObject = ArgsObject, OptionType extends any = any> = (x: string, y: Args) => OptionType;
|
|
97
|
-
|
|
109
|
+
/** {@link OptionConfig} with a specified value type */
|
|
110
|
+
export declare const TypedOptionConfig: <OptionType, Args extends ArgsObject = ArgsObject>(type: z.ZodType<OptionType, z.ZodTypeDef, OptionType>) => z.ZodObject<{
|
|
98
111
|
name: z.ZodString;
|
|
99
112
|
description: z.ZodString;
|
|
100
113
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
@@ -136,7 +149,7 @@ export type TypedOptionConfig<T, A extends ArgsObject = ArgsObject> = z.infer<Re
|
|
|
136
149
|
* @see OptionConfig
|
|
137
150
|
* @see ArrayOptionConfig
|
|
138
151
|
*/
|
|
139
|
-
export declare const ArrayOptionConfig: <T, A extends
|
|
152
|
+
export declare const ArrayOptionConfig: <T, A extends ArgsObject = ArgsObject>(type: z.ZodType<T, z.ZodTypeDef, T>) => z.ZodObject<{
|
|
140
153
|
type: z.ZodOptional<z.ZodEnum<["number"]>>;
|
|
141
154
|
name: z.ZodString;
|
|
142
155
|
description: z.ZodString;
|
|
@@ -179,15 +192,24 @@ export declare const ArrayOptionConfig: <T, A extends object = object>(type: z.Z
|
|
|
179
192
|
* This type represents an array option, which can be specified multiple times.
|
|
180
193
|
*/
|
|
181
194
|
export type ArrayOptionConfig<T = unknown> = z.infer<ReturnType<typeof ArrayOptionConfig<z.ZodType<T>>>>;
|
|
182
|
-
|
|
183
|
-
export declare const
|
|
184
|
-
|
|
185
|
-
export declare const
|
|
195
|
+
/** The default prefixes for options */
|
|
196
|
+
export declare const DEFAULT_OPT_FULL_PREFIX = "--";
|
|
197
|
+
/** The default prefix for option aliases */
|
|
198
|
+
export declare const DEFAULT_OPT_SHORT_PREFIX = "-";
|
|
186
199
|
export type Prefixes = {
|
|
187
|
-
|
|
200
|
+
normalPrefix: string;
|
|
188
201
|
aliasPrefix: string;
|
|
189
|
-
|
|
190
|
-
|
|
202
|
+
};
|
|
203
|
+
export type Names = {
|
|
204
|
+
name: string;
|
|
205
|
+
aliases: string[];
|
|
206
|
+
};
|
|
207
|
+
/** Names with prefixes built-in */
|
|
208
|
+
export type QualifiedNames = {
|
|
209
|
+
name: string;
|
|
210
|
+
aliases: string[];
|
|
211
|
+
negationName: string;
|
|
212
|
+
negationAliases: string[];
|
|
191
213
|
};
|
|
192
214
|
/** @internal */
|
|
193
215
|
export type ArgvValue<T> = {
|
|
@@ -217,29 +239,43 @@ export type ArgvValue<T> = {
|
|
|
217
239
|
* })
|
|
218
240
|
* ```
|
|
219
241
|
*/
|
|
220
|
-
export declare class MassargOption<OptionType extends any = unknown, Args extends ArgsObject = ArgsObject> {
|
|
242
|
+
export declare class MassargOption<OptionType extends any = unknown, Args extends ArgsObject = ArgsObject> implements OptionConfig<OptionType, Args> {
|
|
221
243
|
name: string;
|
|
222
244
|
description: string;
|
|
223
245
|
defaultValue?: OptionType;
|
|
224
246
|
aliases: string[];
|
|
225
247
|
parse: Parser<Args, OptionType>;
|
|
248
|
+
/**
|
|
249
|
+
* Whether this option can be used multiple times. Any passed values will end up in an array
|
|
250
|
+
* instead of each usage overwriting the existing value.
|
|
251
|
+
*/
|
|
226
252
|
isArray: boolean;
|
|
253
|
+
/** Whether this option is required. Failing to specify this option will throw an error. */
|
|
227
254
|
isRequired: boolean;
|
|
228
255
|
isDefault: boolean;
|
|
229
256
|
outputName?: string;
|
|
230
257
|
constructor(options: OptionConfig<OptionType, Args>);
|
|
258
|
+
/**
|
|
259
|
+
* Create a typed option from a configuration. Currently supports `number` options which
|
|
260
|
+
* are automatically transformed from `string` to `number`.
|
|
261
|
+
*/
|
|
231
262
|
static fromTypedConfig<T = unknown, A extends ArgsObject = ArgsObject>(config: TypedOptionConfig<T, A>): MassargOption<T>;
|
|
263
|
+
/**
|
|
264
|
+
* Returns the key which this option outputs to in the final object.
|
|
265
|
+
*
|
|
266
|
+
* @default The camelCase version of this option's name.
|
|
267
|
+
*
|
|
268
|
+
* Can be overridden with {@link outputName}.
|
|
269
|
+
*/
|
|
232
270
|
getOutputName(): string;
|
|
271
|
+
/** @internal */
|
|
233
272
|
parseDetails(argv: string[], options: ArgsObject, prefixes: Prefixes): ArgvValue<OptionType>;
|
|
273
|
+
/** Get the help string for this option */
|
|
234
274
|
helpString(): string;
|
|
235
275
|
/** Returns true if the flag (including any prefixes) matches the name or aliases */
|
|
236
276
|
isMatch(arg: string, prefixes: Prefixes): boolean;
|
|
237
|
-
/**
|
|
238
|
-
|
|
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;
|
|
277
|
+
/** Return the finalized names that will cause this option to match. */
|
|
278
|
+
qualifiedNames(prefixes: Prefixes): QualifiedNames;
|
|
243
279
|
}
|
|
244
280
|
/**
|
|
245
281
|
* An option that can be passed to a command.
|
|
@@ -262,15 +298,16 @@ export declare class MassargNumber extends MassargOption<number> {
|
|
|
262
298
|
parseDetails(argv: string[], options: ArgsObject, prefixes: Prefixes): ArgvValue<number>;
|
|
263
299
|
}
|
|
264
300
|
/**
|
|
265
|
-
*
|
|
301
|
+
* A boolean option that can be passed to a command.
|
|
266
302
|
*
|
|
267
303
|
* A flag is an option that is either present or not. It can be used to toggle
|
|
268
304
|
* a boolean value, or to indicate that a command should be run in a different
|
|
269
305
|
* mode.
|
|
270
306
|
*
|
|
271
|
-
* A flag can be negated by
|
|
272
|
-
*
|
|
273
|
-
*
|
|
307
|
+
* A flag can be negated by using `negatable: true`. By default, the negated name is the same
|
|
308
|
+
* as the option name, prefixed by `no-`, and each of the aliases will be uppercased.
|
|
309
|
+
* For example, `--verbose` and `--no-verbose`, or `-v` and `-V`.
|
|
310
|
+
* This behavior can be overridden by the `negatedName` and `negatedAliases` options.
|
|
274
311
|
*
|
|
275
312
|
* @example
|
|
276
313
|
* ```ts
|
|
@@ -283,10 +320,17 @@ export declare class MassargNumber extends MassargOption<number> {
|
|
|
283
320
|
* ```
|
|
284
321
|
*/
|
|
285
322
|
export declare class MassargFlag extends MassargOption<boolean> {
|
|
323
|
+
/** Whether this flag may be negated using `negationName` or `negationAliases`. */
|
|
286
324
|
negatable: boolean;
|
|
325
|
+
/** The negation name of this flag, which can be used with the full option notation. */
|
|
326
|
+
negationName: string;
|
|
327
|
+
/** The negation aliases of this flag, which can be used with the shorthand option notation. */
|
|
328
|
+
negationAliases: string[];
|
|
287
329
|
constructor(options: FlagConfig);
|
|
288
330
|
parseDetails(argv: string[], _options: ArgsObject, prefixes: Prefixes): ArgvValue<boolean>;
|
|
331
|
+
qualifiedNames(prefixes: Prefixes): QualifiedNames;
|
|
289
332
|
}
|
|
333
|
+
/** A flag that can be passed to a command to show the help message. */
|
|
290
334
|
export declare class MassargHelpFlag extends MassargFlag {
|
|
291
335
|
constructor(config?: Partial<Omit<OptionConfig<boolean>, 'parse'>>);
|
|
292
336
|
}
|
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;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
|
|
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;;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AU,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;IAyC1F,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc;CAOnD;AAED,uEAAuE;AACvE,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.
|
|
3
|
+
exports.MassargHelpFlag = exports.MassargFlag = exports.MassargNumber = exports.MassargOption = exports.DEFAULT_OPT_SHORT_PREFIX = exports.DEFAULT_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");
|
|
@@ -43,12 +43,32 @@ const OptionConfig = (type) => zod_1.z.object({
|
|
|
43
43
|
outputName: zod_1.z.string().optional(),
|
|
44
44
|
});
|
|
45
45
|
exports.OptionConfig = OptionConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for a flag (boolean argument) that can be passed to a command.
|
|
48
|
+
*/
|
|
46
49
|
exports.FlagConfig = (0, exports.OptionConfig)(zod_1.z.any())
|
|
47
50
|
.omit({ parse: true, isDefault: true })
|
|
48
51
|
.merge(zod_1.z.object({
|
|
49
52
|
/** Whether the flag can be negated, e.g. `--no-verbose` */
|
|
50
53
|
negatable: zod_1.z.boolean().optional(),
|
|
54
|
+
/**
|
|
55
|
+
* Negation name of the option, which can be used with the full option notation.
|
|
56
|
+
*
|
|
57
|
+
* Defaults to `no-{name}` of your option's name, e.g. `verbose` becomes `--no-verbose`.
|
|
58
|
+
*
|
|
59
|
+
* To use this, you must set `negatable: true` in the option's configuration.
|
|
60
|
+
*/
|
|
61
|
+
negationName: zod_1.z.string().optional(),
|
|
62
|
+
/**
|
|
63
|
+
* Negation aliases for the option, which can be used with the shorthand option notation.
|
|
64
|
+
*
|
|
65
|
+
* Defaults to uppercase of each of the aliases provided, e.g. `q` becomes `-Q`.
|
|
66
|
+
*
|
|
67
|
+
* To use this, you must set `negatable: true` in the option's configuration.
|
|
68
|
+
*/
|
|
69
|
+
negationAliases: zod_1.z.string().array().optional(),
|
|
51
70
|
}));
|
|
71
|
+
/** {@link OptionConfig} with a specified value type */
|
|
52
72
|
const TypedOptionConfig = (type) => (0, exports.OptionConfig)(type).merge(zod_1.z.object({
|
|
53
73
|
type: zod_1.z.enum(['number']).optional(),
|
|
54
74
|
}));
|
|
@@ -63,11 +83,10 @@ zod_1.z.object({
|
|
|
63
83
|
defaultValue: zod_1.z.array(type).optional(),
|
|
64
84
|
}));
|
|
65
85
|
exports.ArrayOptionConfig = ArrayOptionConfig;
|
|
66
|
-
|
|
67
|
-
exports.
|
|
68
|
-
|
|
69
|
-
exports.
|
|
70
|
-
exports.NEGATE_SHORT_PREFIX = '^';
|
|
86
|
+
/** The default prefixes for options */
|
|
87
|
+
exports.DEFAULT_OPT_FULL_PREFIX = '--';
|
|
88
|
+
/** The default prefix for option aliases */
|
|
89
|
+
exports.DEFAULT_OPT_SHORT_PREFIX = '-';
|
|
71
90
|
/**
|
|
72
91
|
* An option that can be passed to a command.
|
|
73
92
|
*
|
|
@@ -103,6 +122,10 @@ class MassargOption {
|
|
|
103
122
|
this.isRequired = options.required ?? false;
|
|
104
123
|
this.outputName = options.outputName;
|
|
105
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Create a typed option from a configuration. Currently supports `number` options which
|
|
127
|
+
* are automatically transformed from `string` to `number`.
|
|
128
|
+
*/
|
|
106
129
|
static fromTypedConfig(config) {
|
|
107
130
|
switch (config.type) {
|
|
108
131
|
case 'number':
|
|
@@ -110,9 +133,17 @@ class MassargOption {
|
|
|
110
133
|
}
|
|
111
134
|
return new MassargOption(config);
|
|
112
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the key which this option outputs to in the final object.
|
|
138
|
+
*
|
|
139
|
+
* @default The camelCase version of this option's name.
|
|
140
|
+
*
|
|
141
|
+
* Can be overridden with {@link outputName}.
|
|
142
|
+
*/
|
|
113
143
|
getOutputName() {
|
|
114
144
|
return this.outputName || (0, utils_1.toCamelCase)(this.name);
|
|
115
145
|
}
|
|
146
|
+
/** @internal */
|
|
116
147
|
parseDetails(argv, options, prefixes) {
|
|
117
148
|
let input = '';
|
|
118
149
|
try {
|
|
@@ -141,38 +172,27 @@ class MassargOption {
|
|
|
141
172
|
throw e;
|
|
142
173
|
}
|
|
143
174
|
}
|
|
175
|
+
/** Get the help string for this option */
|
|
144
176
|
helpString() {
|
|
145
177
|
const aliases = this.aliases.length ? `|${this.aliases.join('|-')}` : '';
|
|
146
178
|
return `--${this.name}${aliases} ${this.description}`;
|
|
147
179
|
}
|
|
148
180
|
/** Returns true if the flag (including any prefixes) matches the name or aliases */
|
|
149
181
|
isMatch(arg, prefixes) {
|
|
150
|
-
const
|
|
151
|
-
return
|
|
182
|
+
const qualifiedNames = this.qualifiedNames(prefixes);
|
|
183
|
+
return (arg === qualifiedNames.name ||
|
|
184
|
+
arg === qualifiedNames.negationName ||
|
|
185
|
+
qualifiedNames.aliases.includes(arg) ||
|
|
186
|
+
qualifiedNames.negationAliases.includes(arg));
|
|
152
187
|
}
|
|
153
|
-
/**
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (arg.startsWith(negateFlagPrefix)) {
|
|
162
|
-
return arg.slice(negateFlagPrefix.length);
|
|
163
|
-
}
|
|
164
|
-
if (arg.startsWith(optionPrefix)) {
|
|
165
|
-
return arg.slice(optionPrefix.length);
|
|
166
|
-
}
|
|
167
|
-
// negate short prefix
|
|
168
|
-
if (arg.startsWith(negateAliasPrefix)) {
|
|
169
|
-
return arg.slice(negateAliasPrefix.length);
|
|
170
|
-
}
|
|
171
|
-
// short prefix
|
|
172
|
-
if (arg.startsWith(aliasPrefix) || arg.startsWith(negateAliasPrefix)) {
|
|
173
|
-
return arg.slice(aliasPrefix.length);
|
|
174
|
-
}
|
|
175
|
-
return '<blank>';
|
|
188
|
+
/** Return the finalized names that will cause this option to match. */
|
|
189
|
+
qualifiedNames(prefixes) {
|
|
190
|
+
return {
|
|
191
|
+
name: prefixes.normalPrefix + this.name,
|
|
192
|
+
aliases: this.aliases.map((a) => prefixes.aliasPrefix + a),
|
|
193
|
+
negationName: '',
|
|
194
|
+
negationAliases: [],
|
|
195
|
+
};
|
|
176
196
|
}
|
|
177
197
|
}
|
|
178
198
|
exports.MassargOption = MassargOption;
|
|
@@ -227,15 +247,16 @@ class MassargNumber extends MassargOption {
|
|
|
227
247
|
}
|
|
228
248
|
exports.MassargNumber = MassargNumber;
|
|
229
249
|
/**
|
|
230
|
-
*
|
|
250
|
+
* A boolean option that can be passed to a command.
|
|
231
251
|
*
|
|
232
252
|
* A flag is an option that is either present or not. It can be used to toggle
|
|
233
253
|
* a boolean value, or to indicate that a command should be run in a different
|
|
234
254
|
* mode.
|
|
235
255
|
*
|
|
236
|
-
* A flag can be negated by
|
|
237
|
-
*
|
|
238
|
-
*
|
|
256
|
+
* A flag can be negated by using `negatable: true`. By default, the negated name is the same
|
|
257
|
+
* as the option name, prefixed by `no-`, and each of the aliases will be uppercased.
|
|
258
|
+
* For example, `--verbose` and `--no-verbose`, or `-v` and `-V`.
|
|
259
|
+
* This behavior can be overridden by the `negatedName` and `negatedAliases` options.
|
|
239
260
|
*
|
|
240
261
|
* @example
|
|
241
262
|
* ```ts
|
|
@@ -254,11 +275,14 @@ class MassargFlag extends MassargOption {
|
|
|
254
275
|
parse: () => true,
|
|
255
276
|
});
|
|
256
277
|
this.negatable = options.negatable ?? false;
|
|
278
|
+
this.negationName = options.negationName ?? `no-${options.name}`;
|
|
279
|
+
this.negationAliases = options.negationAliases ?? this.aliases.map((a) => a.toUpperCase());
|
|
257
280
|
}
|
|
258
281
|
parseDetails(argv, _options, prefixes) {
|
|
259
282
|
try {
|
|
260
|
-
const
|
|
261
|
-
|
|
283
|
+
const qualifiedNames = this.qualifiedNames(prefixes);
|
|
284
|
+
const isNegation = (qualifiedNames.negationName && argv[0] === qualifiedNames.negationName) ||
|
|
285
|
+
(qualifiedNames.negationAliases.length && qualifiedNames.negationAliases.includes(argv[0]));
|
|
262
286
|
if (!this.negatable && isNegation) {
|
|
263
287
|
throw new error_1.ParseError({
|
|
264
288
|
path: [this.name],
|
|
@@ -292,8 +316,16 @@ class MassargFlag extends MassargOption {
|
|
|
292
316
|
throw e;
|
|
293
317
|
}
|
|
294
318
|
}
|
|
319
|
+
qualifiedNames(prefixes) {
|
|
320
|
+
return {
|
|
321
|
+
...super.qualifiedNames(prefixes),
|
|
322
|
+
negationName: prefixes.normalPrefix + this.negationName,
|
|
323
|
+
negationAliases: this.negationAliases.map((a) => prefixes.aliasPrefix + a),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
295
326
|
}
|
|
296
327
|
exports.MassargFlag = MassargFlag;
|
|
328
|
+
/** A flag that can be passed to a command to show the help message. */
|
|
297
329
|
class MassargHelpFlag extends MassargFlag {
|
|
298
330
|
constructor(config = {}) {
|
|
299
331
|
super({
|
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;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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oBACnB,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAC/D,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI;oBACtB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO;iBAC7B,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;IAED,cAAc,CAAC,QAAkB;QAC/B,OAAO;YACL,GAAG,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC;YACjC,YAAY,EAAE,QAAQ,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY;YACvD,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC;SAC3E,CAAA;IACH,CAAC;CACF;AAlED,kCAkEC;AAED,uEAAuE;AACvE,MAAa,eAAgB,SAAQ,WAAW;IAC9C,YAAY,SAAwD,EAAE;QACpE,KAAK,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
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Flexible, powerful, and simple command/argument parser for CLI applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shell",
|
|
@@ -19,24 +19,28 @@
|
|
|
19
19
|
"dev": "tsc --watch",
|
|
20
20
|
"cmd": "ts-node src/sample.ts",
|
|
21
21
|
"test": "jest",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
22
|
+
"docs:build": "cd docs && pnpm build",
|
|
23
|
+
"docs:watch": "cd docs && pnpm start",
|
|
24
|
+
"docs:deploy": "pnpm docs:build && gh-pages -d docs",
|
|
25
|
+
"semantic-release": "semantic-release",
|
|
26
|
+
"changelog": "conventional-changelog -i CHANGELOG.md -s -r 0; echo \"# Change Log\n\n$(cat CHANGELOG.md)\" > CHANGELOG.md"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
29
|
"@semantic-release/changelog": "^6.0.3",
|
|
28
30
|
"@semantic-release/exec": "^6.0.3",
|
|
29
31
|
"@semantic-release/git": "^10.0.1",
|
|
30
|
-
"@
|
|
31
|
-
"@types/
|
|
32
|
-
"
|
|
32
|
+
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
33
|
+
"@types/jest": "^29.5.11",
|
|
34
|
+
"@types/node": "^20.11.10",
|
|
35
|
+
"conventional-changelog": "^5.1.0",
|
|
36
|
+
"conventional-changelog-cli": "^4.1.0",
|
|
37
|
+
"gh-pages": "^6.1.1",
|
|
33
38
|
"jest": "^29.7.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"ts-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"typescript": "^5.2.2"
|
|
39
|
+
"prettier": "^3.2.4",
|
|
40
|
+
"semantic-release": "^23.0.0",
|
|
41
|
+
"ts-jest": "^29.1.2",
|
|
42
|
+
"ts-node": "^10.9.2",
|
|
43
|
+
"typescript": "^5.3.3"
|
|
40
44
|
},
|
|
41
45
|
"dependencies": {
|
|
42
46
|
"zod": "^3.22.4"
|
package/style.js
CHANGED
|
@@ -18,9 +18,9 @@ exports.ansiStyles = {
|
|
|
18
18
|
exports.ansiColors = {
|
|
19
19
|
red: '\x1b[31m',
|
|
20
20
|
green: '\x1b[32m',
|
|
21
|
-
yellow: '\x1b[33m',
|
|
21
|
+
yellow: '\x1b[33m', // warning
|
|
22
22
|
blue: '\x1b[34m',
|
|
23
|
-
magenta: '\x1b[35m',
|
|
23
|
+
magenta: '\x1b[35m', // error
|
|
24
24
|
cyan: '\x1b[36m',
|
|
25
25
|
white: '\x1b[37m',
|
|
26
26
|
gray: '\x1b[90m',
|
|
@@ -36,7 +36,7 @@ exports.ansiColors = {
|
|
|
36
36
|
exports.StringStyle = zod_1.default.object({
|
|
37
37
|
bold: zod_1.default.boolean().optional(),
|
|
38
38
|
underline: zod_1.default.boolean().optional(),
|
|
39
|
-
color: (0, utils_1.
|
|
39
|
+
color: (0, utils_1._zodEnumFromObjKeys)(exports.ansiColors).optional(),
|
|
40
40
|
reset: zod_1.default.boolean().default(true).optional(),
|
|
41
41
|
});
|
|
42
42
|
function format(string, style = {}) {
|
package/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,mCAA6C;AAC7C,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,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU,EAAE,UAAU;IAC9B,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU,EAAE,QAAQ;IAC7B,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IACh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MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;AAC3C,CAAC;AAFD,gCAEC"}
|
package/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
/** @internal */
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
3
|
+
export declare function _setOrPush<T>(newValue: unknown, currentValue: T[] | T | undefined, isArray: boolean): T;
|
|
4
|
+
/** A value that can be stringified using one of the util functions. */
|
|
5
|
+
export type Parseable = string | number | boolean | null | undefined | Record<string, unknown>;
|
|
5
6
|
/** A type that makes all properties of an object required, recursively. */
|
|
6
7
|
export type DeepRequired<T> = {
|
|
7
8
|
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : NonNullable<T[P]>;
|
|
@@ -20,9 +21,9 @@ export declare function strConcat(...strs: (Parseable | Parseable[])[]): string;
|
|
|
20
21
|
*/
|
|
21
22
|
export declare function indent(str: Parseable | Parseable[], indent?: number): string;
|
|
22
23
|
/** @internal */
|
|
23
|
-
export declare function
|
|
24
|
+
export declare function _zodEnumFromObjKeys<K extends string>(obj: Record<K, any>): z.ZodEnum<[K, ...K[]]>;
|
|
24
25
|
/** @internal */
|
|
25
|
-
export declare function
|
|
26
|
+
export declare function _deepMerge<T1, T2>(obj1: T1, obj2: T2): NonNullable<T1> & NonNullable<T2>;
|
|
26
27
|
export declare function capitalize(str: string): string;
|
|
27
28
|
/**
|
|
28
29
|
* Splits a name into words, using camelCase, PascalCase, snake_case, and kebab-case or
|
|
@@ -32,5 +33,4 @@ export declare function splitWords(str: string): string[];
|
|
|
32
33
|
export declare function toCamelCase(str: string): string;
|
|
33
34
|
export declare function toPascalCase(str: string): string;
|
|
34
35
|
export declare function getErrorMessage(err: unknown): string;
|
|
35
|
-
export {};
|
|
36
36
|
//# sourceMappingURL=utils.d.ts.map
|