massarg 1.0.7-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.js ADDED
@@ -0,0 +1,410 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MassargHelpCommand = exports.MassargCommand = exports.CommandConfig = void 0;
4
+ const zod_1 = require("zod");
5
+ const error_1 = require("./error");
6
+ const help_1 = require("./help");
7
+ const option_1 = require("./option");
8
+ const utils_1 = require("./utils");
9
+ const example_1 = require("./example");
10
+ const style_1 = require("./style");
11
+ const CommandConfig = (args) => zod_1.z.object({
12
+ /** Command name */
13
+ name: zod_1.z.string(),
14
+ /** Command description, displayed in the help output */
15
+ description: zod_1.z.string(),
16
+ /** Command aliases */
17
+ aliases: zod_1.z.string().array().optional(),
18
+ /**
19
+ * Function used when invoking this command. It receives the parsed options and the primary
20
+ * instance of Massarg used to invoke this command (the top-level instance)
21
+ */
22
+ run: zod_1.z
23
+ .function()
24
+ .args(args, zod_1.z.any())
25
+ .returns(zod_1.z.union([zod_1.z.promise(zod_1.z.void()), zod_1.z.void()])),
26
+ /** Prefix of options understood by this command */
27
+ optionPrefix: zod_1.z.string().default(option_1.OPT_FULL_PREFIX).optional(),
28
+ /** Prefix of negated flags understood by this command */
29
+ negateFlagPrefix: zod_1.z.string().default(option_1.NEGATE_FULL_PREFIX).optional(),
30
+ /** Prefix of aliases of options understood by this command */
31
+ optionAliasPrefix: zod_1.z.string().default(option_1.OPT_SHORT_PREFIX).optional(),
32
+ /** Prefix of aliases of negated flags understood by this command */
33
+ negateAliasPrefix: zod_1.z.string().default(option_1.NEGATE_SHORT_PREFIX).optional(),
34
+ });
35
+ exports.CommandConfig = CommandConfig;
36
+ /**
37
+ * A command is a named function that can be invoked with a set of options.
38
+ *
39
+ * Commands can have sub-commands, which can have their own sub-commands, and so on.
40
+ *
41
+ * Options are not inherited by sub-commands, but their parsed values are passed down when
42
+ * invoking a sub-command. This works recursively.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * massarg(options).command({
47
+ * name: 'foo',
48
+ * description: 'foo command',
49
+ * run: (options, instance) => {
50
+ * console.log(options, instance)
51
+ * },
52
+ * })
53
+ * ```
54
+ */
55
+ class MassargCommand {
56
+ constructor(options, parent) {
57
+ this.commands = [];
58
+ this.options = [];
59
+ this.examples = [];
60
+ this.args = {};
61
+ this.optionPrefix = option_1.OPT_FULL_PREFIX;
62
+ this.negateFlagPrefix = option_1.NEGATE_FULL_PREFIX;
63
+ this.optionAliasPrefix = option_1.OPT_SHORT_PREFIX;
64
+ this.negateAliasPrefix = option_1.NEGATE_SHORT_PREFIX;
65
+ (0, exports.CommandConfig)(zod_1.z.any()).parse(options);
66
+ this.name = options.name;
67
+ this.description = options.description;
68
+ this.aliases = options.aliases ?? [];
69
+ this._run = options.run;
70
+ this._helpConfig = {};
71
+ this.parent = parent;
72
+ // TODO mix these with help config
73
+ this.optionPrefix = options.optionPrefix ?? this.optionPrefix;
74
+ this.negateFlagPrefix = options.negateFlagPrefix ?? this.negateFlagPrefix;
75
+ this.optionAliasPrefix = options.optionAliasPrefix ?? this.optionAliasPrefix;
76
+ this.negateAliasPrefix = options.negateAliasPrefix ?? this.negateAliasPrefix;
77
+ }
78
+ get optionPrefixes() {
79
+ return this.getPrefixes();
80
+ }
81
+ getPrefixes() {
82
+ return {
83
+ optionPrefix: this.optionPrefix,
84
+ aliasPrefix: this.optionAliasPrefix,
85
+ negateFlagPrefix: this.negateFlagPrefix,
86
+ negateAliasPrefix: this.negateAliasPrefix,
87
+ };
88
+ }
89
+ get helpConfig() {
90
+ if (this.parent) {
91
+ return (0, utils_1.deepMerge)(this.parent.helpConfig, this._helpConfig);
92
+ }
93
+ return (0, utils_1.deepMerge)(help_1.defaultHelpConfig, (0, utils_1.deepMerge)({
94
+ optionOptions: {
95
+ namePrefix: this.optionPrefix,
96
+ aliasPrefix: this.optionAliasPrefix,
97
+ negatePrefix: this.negateFlagPrefix,
98
+ negateAliasPrefix: this.negateAliasPrefix,
99
+ },
100
+ }, this._helpConfig));
101
+ }
102
+ command(config) {
103
+ try {
104
+ const command = config instanceof MassargCommand ? config : new MassargCommand(config);
105
+ const existing = this.commands.find((c) => c.name === command.name);
106
+ if (existing) {
107
+ throw new error_1.ValidationError({
108
+ code: 'duplicate_command',
109
+ message: `Command "${command.name}" already exists`,
110
+ path: [this.name, command.name],
111
+ });
112
+ }
113
+ command.parent = this;
114
+ this.commands.push(command);
115
+ return this;
116
+ }
117
+ catch (e) {
118
+ if ((0, error_1.isZodError)(e)) {
119
+ e = new error_1.ValidationError({
120
+ path: [this.name, config.name, ...e.issues[0].path.map((p) => p.toString())],
121
+ code: e.issues[0].code,
122
+ message: e.issues[0].message,
123
+ });
124
+ }
125
+ this.printError(e);
126
+ throw e;
127
+ }
128
+ }
129
+ flag(config) {
130
+ try {
131
+ const flag = config instanceof option_1.MassargFlag ? config : new option_1.MassargFlag(config);
132
+ this.assertNotDuplicate(flag, 'flag');
133
+ this.options.push(flag);
134
+ return this;
135
+ }
136
+ catch (e) {
137
+ if ((0, error_1.isZodError)(e)) {
138
+ e = new error_1.ValidationError({
139
+ path: [this.name, config.name, ...e.issues[0].path.map((p) => p.toString())],
140
+ code: e.issues[0].code,
141
+ message: e.issues[0].message,
142
+ });
143
+ }
144
+ this.printError(e);
145
+ throw e;
146
+ }
147
+ }
148
+ option(config) {
149
+ try {
150
+ const option = config instanceof option_1.MassargOption
151
+ ? config
152
+ : option_1.MassargOption.fromTypedConfig(config);
153
+ this.assertNotDuplicate(option, 'option');
154
+ this.assertOnlyOneDefault(option);
155
+ this.options.push(option);
156
+ return this;
157
+ }
158
+ catch (e) {
159
+ if ((0, error_1.isZodError)(e)) {
160
+ e = new error_1.ValidationError({
161
+ path: [this.name, config.name, ...e.issues[0].path.map((p) => p.toString())],
162
+ code: e.issues[0].code,
163
+ message: e.issues[0].message,
164
+ });
165
+ }
166
+ this.printError(e);
167
+ throw e;
168
+ }
169
+ }
170
+ assertNotDuplicate(option, type) {
171
+ const existingName = this.options.find((c) => c.name === option.name);
172
+ if (existingName) {
173
+ throw new error_1.ValidationError({
174
+ code: `duplicate_${type}_name`,
175
+ message: `${(0, utils_1.capitalize)(type)} name "${existingName.name}" already exists`,
176
+ path: [this.name, option.name],
177
+ });
178
+ }
179
+ const existingAlias = this.options.find((c) => c.aliases.some((a) => option.aliases.includes(a)));
180
+ if (existingAlias) {
181
+ const alias = option.aliases.find((a) => existingAlias.aliases.includes(a));
182
+ throw new error_1.ValidationError({
183
+ code: 'duplicate_option_alias',
184
+ message: `Option alias "${alias}" already exists on option "${existingAlias.name}"`,
185
+ path: [this.name, option.name],
186
+ });
187
+ }
188
+ }
189
+ assertOnlyOneDefault(option) {
190
+ if (option.isDefault) {
191
+ const defaultOption = this.options.find((o) => o.isDefault);
192
+ if (defaultOption) {
193
+ throw new error_1.ValidationError({
194
+ code: 'duplicate_default_option',
195
+ message: `Option "${option.name}" cannot be set as default because option "${defaultOption.name}" is already set as default`,
196
+ path: [this.name, option.name],
197
+ });
198
+ }
199
+ }
200
+ }
201
+ /**
202
+ * Adds an example to this command.
203
+ *
204
+ * An example is a description of how to use the command, with an example input and output.
205
+ *
206
+ * At least one of `description`, `input` or `output` must be provided, but neither alone is
207
+ * required.
208
+ */
209
+ example(config) {
210
+ this.examples.push(new example_1.MassargExample(config));
211
+ return this;
212
+ }
213
+ /**
214
+ * Configure the help output for this (and all child) commands.
215
+ *
216
+ * You can automatically bind the help command to this command, and/or bind the help option
217
+ * to this command.
218
+ *
219
+ * If you don't opt-in to this behavior with `bindCommand` or `bindOption`, you can still
220
+ * access the help output via `this.helpString()` and `this.printHelp()`.
221
+ */
222
+ help(config) {
223
+ this._helpConfig = help_1.HelpConfig.parse(config);
224
+ let ret = this;
225
+ if (this.helpConfig.bindCommand) {
226
+ ret = ret.command(new MassargHelpCommand());
227
+ }
228
+ if (this.helpConfig.bindOption) {
229
+ ret = ret.option(new option_1.MassargHelpFlag());
230
+ }
231
+ return this;
232
+ }
233
+ /**
234
+ * Configure the main function for this command. This command will run when no sub-commands
235
+ * are provided.
236
+ *
237
+ * If none is provided, help will be printed.
238
+ */
239
+ main(run) {
240
+ this._run = run;
241
+ return this;
242
+ }
243
+ /**
244
+ * Parse the given arguments and run the command or sub-commands along with the given options
245
+ * and flags.
246
+ *
247
+ * To parse the arguments without running any commands and only get the output args,
248
+ * use `getArgs` instead.
249
+ */
250
+ parse(argv = process.argv.slice(2), args, parent) {
251
+ try {
252
+ this.getArgs(argv, args, parent, true);
253
+ }
254
+ catch (e) {
255
+ this.printError(e);
256
+ }
257
+ }
258
+ printError(e) {
259
+ const message = (0, utils_1.getErrorMessage)(e);
260
+ console.error((0, style_1.format)(message, { color: 'red' }));
261
+ }
262
+ parseOption(arg, argv) {
263
+ const prefixes = { ...this.optionPrefixes };
264
+ const option = this.options.find((o) => o.isMatch(arg, prefixes));
265
+ if (!option) {
266
+ throw new error_1.ValidationError({
267
+ path: [option_1.MassargOption.findNameInArg(arg, prefixes)],
268
+ code: 'unknown_option',
269
+ message: 'Unknown option',
270
+ });
271
+ }
272
+ const res = option.parseDetails([arg, ...argv], { ...this.args }, prefixes);
273
+ this.args[res.key] = (0, utils_1.setOrPush)(res.value, this.args[res.key], option.isArray);
274
+ return res.argv;
275
+ }
276
+ getArgs(argv, args, parent, parseCommands = false) {
277
+ try {
278
+ let _args = { ...this.args, ...args };
279
+ let _argv = [...argv];
280
+ const _a = this.args;
281
+ // fill defaults
282
+ for (const option of this.options) {
283
+ if (option.defaultValue !== undefined && _a[option.name] === undefined) {
284
+ _args[option.getOutputName()] = option.defaultValue;
285
+ }
286
+ }
287
+ // parse options
288
+ while (_argv.length) {
289
+ const arg = _argv.shift();
290
+ // make sure option exists
291
+ const found = this.options.find((o) => o.isMatch(arg, this.optionPrefixes));
292
+ if (found) {
293
+ if (this.helpConfig.bindOption && found.name === 'help') {
294
+ if (parseCommands) {
295
+ this.printHelp();
296
+ return;
297
+ }
298
+ return this.args;
299
+ }
300
+ _argv = this.parseOption(arg, _argv);
301
+ _args = { ..._args, ...this.args };
302
+ continue;
303
+ }
304
+ // if not, try see if it's a command
305
+ const command = this.commands.find((c) => c.name === arg || c.aliases.includes(arg));
306
+ if (command) {
307
+ // this is dry run, just exit
308
+ if (!parseCommands) {
309
+ return command.getArgs(_argv, this.args, parent ?? this, false);
310
+ // break
311
+ }
312
+ // this is real run, parse command, pass unparsed args
313
+ return command.parse(_argv, this.args, parent ?? this);
314
+ }
315
+ // default option - passes arg value even without flag name
316
+ const defaultOption = this.options.find((o) => o.isDefault);
317
+ if (defaultOption) {
318
+ this.parseOption(`--${defaultOption.name}`, [arg]);
319
+ continue;
320
+ }
321
+ // not parsed by any step, add to extra key
322
+ _a.extra ??= [];
323
+ _a.extra.push(arg);
324
+ }
325
+ // merge args
326
+ this.args = { ...this.args, ..._args };
327
+ this.assertRequired();
328
+ // dry run, just exit
329
+ if (!parseCommands) {
330
+ return this.args;
331
+ }
332
+ // no sub command found, run main command
333
+ if (this._run) {
334
+ this._run(this.args, parent ?? this);
335
+ }
336
+ }
337
+ catch (e) {
338
+ if ((0, error_1.isZodError)(e)) {
339
+ e = new error_1.ValidationError({
340
+ path: [this.name, ...e.issues[0].path.map((p) => p.toString())],
341
+ code: e.issues[0].code,
342
+ message: e.issues[0].message,
343
+ });
344
+ }
345
+ throw e;
346
+ }
347
+ }
348
+ assertRequired() {
349
+ const required = this.options.filter((o) => o.isRequired);
350
+ const missing = required.filter((o) => this.args[o.getOutputName()] === undefined);
351
+ if (missing.length) {
352
+ const plural = missing.length > 1 ? 's' : '';
353
+ throw new error_1.ValidationError({
354
+ code: 'missing_required_options',
355
+ message: `Missing required option${plural}: ${missing.map((o) => o.name).join(', ')}`,
356
+ path: [this.name],
357
+ });
358
+ }
359
+ }
360
+ /**
361
+ * Generate the help output for this command, and return it as a string.
362
+ */
363
+ helpString() {
364
+ return new help_1.HelpGenerator(this).generate();
365
+ }
366
+ /**
367
+ * Print the help output for this command.
368
+ */
369
+ printHelp() {
370
+ console.log(this.helpString());
371
+ }
372
+ }
373
+ exports.MassargCommand = MassargCommand;
374
+ class MassargHelpCommand extends MassargCommand {
375
+ constructor(config = {}) {
376
+ const _config = (0, exports.CommandConfig)(zod_1.z.any()).parse({
377
+ name: 'help',
378
+ aliases: ['h'],
379
+ description: 'Print help for this command, or a sub-command if specified',
380
+ run: (args, parent) => {
381
+ if (args.command) {
382
+ const command = parent.commands.find((c) => c.name === args.command);
383
+ if (command) {
384
+ command.printHelp();
385
+ return;
386
+ }
387
+ else {
388
+ throw new error_1.ParseError({
389
+ path: ['command'],
390
+ code: 'unknown_command',
391
+ message: 'Unknown command',
392
+ received: args.command,
393
+ });
394
+ }
395
+ }
396
+ parent.printHelp();
397
+ },
398
+ ...config,
399
+ });
400
+ super(_config);
401
+ this.option({
402
+ name: 'command',
403
+ aliases: ['c'],
404
+ description: 'Command to print help for',
405
+ isDefault: true,
406
+ });
407
+ }
408
+ }
409
+ exports.MassargHelpCommand = MassargHelpCommand;
410
+ //# sourceMappingURL=command.js.map
package/command.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,mCAAiE;AACjE,iCAAqE;AACrE,qCAWiB;AACjB,mCAAyF;AACzF,uCAAyD;AACzD,mCAAgC;AAEzB,MAAM,aAAa,GAAG,CAA0C,IAAwB,EAAE,EAAE,CACjG,OAAC,CAAC,MAAM,CAAC;IACP,mBAAmB;IACnB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,wDAAwD;IACxD,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,sBAAsB;IACtB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;IACtC;;;OAGG;IACH,GAAG,EAAE,OAAC;SACH,QAAQ,EAAE;SACV,I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4DAA4D;YACzE,GAAG,EAAE,CAAC,IAA0B,EAAE,MAAM,EAAE,EAAE;gBAC1C,IAAI,IAAI,CAAC,OAAO,EAAE;oBAChB,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,CAAC,CAAA;oBACpE,IAAI,OAAO,EAAE;wBACX,OAAO,CAAC,SAAS,EAAE,CAAA;wBACnB,OAAM;qBACP;yBAAM;wBACL,MAAM,IAAI,kBAAU,CAAC;4BACnB,IAAI,EAAE,CAAC,SAAS,CAAC;4BACjB,IAAI,EAAE,iBAAiB;4BACvB,OAAO,EAAE,iBAAiB;4BAC1B,QAAQ,EAAE,IAAI,CAAC,OAAO;yBACvB,CAAC,CAAA;qBACH;iBACF;gBACD,MAAM,CAAC,SAAS,EAAE,CAAA;YACpB,CAAC;YACD,GAAG,MAAM;SACU,CAAC,CAAA;QACtB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,MAAM,CAAC;YACV,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,CAAC,GAAG,CAAC;YACd,WAAW,EAAE,2BAA2B;YACxC,SAAS,EAAE,IAAI;SAChB,CAAC,CAAA;IACJ,CAAC;CACF;AAnCD,gDAmCC"}
package/error.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ export type ValidationErrorOptions = {
3
+ path: string[];
4
+ code: string;
5
+ message: string;
6
+ };
7
+ /** This error is thrown when a validation fails. */
8
+ export declare class ValidationError extends Error {
9
+ /** The path to the value that failed validation. */
10
+ path: string[];
11
+ /** The error code. */
12
+ code: string;
13
+ /** The error message. */
14
+ message: string;
15
+ constructor({ path, code, message }: ValidationErrorOptions);
16
+ }
17
+ export type ParseErrorOptions = {
18
+ path: string[];
19
+ code: string;
20
+ message: string;
21
+ received?: unknown;
22
+ };
23
+ /** This error is thrown when a parse fails on an option value. */
24
+ export declare class ParseError extends Error {
25
+ /** The path to the value that failed parsing. */
26
+ path: string[];
27
+ /** The error code. */
28
+ code: string;
29
+ /** The error message. */
30
+ message: string;
31
+ /** The value that failed parsing. */
32
+ received: unknown;
33
+ constructor({ path, code, message, received }: ParseErrorOptions);
34
+ }
35
+ export declare function isZodError(e: unknown): e is z.ZodError;
36
+ //# sourceMappingURL=error.d.ts.map
package/error.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,MAAM,sBAAsB,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtF,oDAAoD;AACpD,qBAAa,eAAgB,SAAQ,KAAK;IACxC,oDAAoD;IACpD,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAA;gBAEH,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,sBAAsB;CAQ5D;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,kEAAkE;AAClE,qBAAa,UAAW,SAAQ,KAAK;IACnC,iDAAiD;IACjD,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,qCAAqC;IACrC,QAAQ,EAAE,OAAO,CAAA;gBAEL,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB;CAYjE;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAEtD"}
package/error.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isZodError = exports.ParseError = exports.ValidationError = void 0;
4
+ const zod_1 = require("zod");
5
+ /** This error is thrown when a validation fails. */
6
+ class ValidationError extends Error {
7
+ constructor({ path, code, message }) {
8
+ const msg = `${path.join('.')}: ${message}`;
9
+ super(msg);
10
+ this.path = path;
11
+ this.code = code;
12
+ this.message = msg;
13
+ this.name = 'ValidationError';
14
+ }
15
+ }
16
+ exports.ValidationError = ValidationError;
17
+ /** This error is thrown when a parse fails on an option value. */
18
+ class ParseError extends Error {
19
+ constructor({ path, code, message, received }) {
20
+ let msg = `${path.join('.')}: ${message}`;
21
+ if (received) {
22
+ msg += ` (received: ${received})`;
23
+ }
24
+ super(msg);
25
+ this.path = path;
26
+ this.code = code;
27
+ this.message = msg;
28
+ this.name = 'ParseError';
29
+ this.received = received;
30
+ }
31
+ }
32
+ exports.ParseError = ParseError;
33
+ function isZodError(e) {
34
+ return e instanceof zod_1.z.ZodError;
35
+ }
36
+ exports.isZodError = isZodError;
37
+ //# sourceMappingURL=error.js.map
package/error.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAIvB,oDAAoD;AACpD,MAAa,eAAgB,SAAQ,KAAK;IAQxC,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAA0B;QACzD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAA;QAC3C,KAAK,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;QAClB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AAhBD,0CAgBC;AASD,kEAAkE;AAClE,MAAa,UAAW,SAAQ,KAAK;IAUnC,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAqB;QAC9D,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAA;QACzC,IAAI,QAAQ,EAAE;YACZ,GAAG,IAAI,eAAe,QAAQ,GAAG,CAAA;SAClC;QACD,KAAK,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;QAClB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAtBD,gCAsBC;AAED,SAAgB,UAAU,CAAC,CAAU;IACnC,OAAO,CAAC,YAAY,OAAC,CAAC,QAAQ,CAAA;AAChC,CAAC;AAFD,gCAEC"}
package/example.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import z from 'zod';
2
+ export declare const ExampleConfig: z.ZodObject<{
3
+ /** Description of the example. This will appear as a title above the input/output line(s). */
4
+ description: z.ZodOptional<z.ZodString>;
5
+ /**
6
+ * Input of the example. This will appear as a line below the description, with a `$` prefix.
7
+ * The prefix can be changed using the `help()` function on the command.
8
+ */
9
+ input: z.ZodOptional<z.ZodString>;
10
+ /**
11
+ * Output of the example. This will appear as a line below the input, with a `>` prefix.
12
+ * The prefix can be changed using the `help()` function on the command.
13
+ */
14
+ output: z.ZodOptional<z.ZodString>;
15
+ }, "strip", z.ZodTypeAny, {
16
+ description?: string | undefined;
17
+ input?: string | undefined;
18
+ output?: string | undefined;
19
+ }, {
20
+ description?: string | undefined;
21
+ input?: string | undefined;
22
+ output?: string | undefined;
23
+ }>;
24
+ export type ExampleConfig = z.infer<typeof ExampleConfig>;
25
+ export declare class MassargExample {
26
+ description: string | undefined;
27
+ input: string | undefined;
28
+ output: string | undefined;
29
+ constructor(config: ExampleConfig);
30
+ }
31
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAGnB,eAAO,MAAM,aAAa;IACxB,8FAA8F;;IAE9F;;;OAGG;;IAEH;;;OAGG;;;;;;;;;;EAEH,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEzD,qBAAa,cAAc;IACzB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;gBAEd,MAAM,EAAE,aAAa;CAiBlC"}
package/example.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MassargExample = exports.ExampleConfig = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const error_1 = require("./error");
9
+ exports.ExampleConfig = zod_1.default.object({
10
+ /** Description of the example. This will appear as a title above the input/output line(s). */
11
+ description: zod_1.default.string().optional(),
12
+ /**
13
+ * Input of the example. This will appear as a line below the description, with a `$` prefix.
14
+ * The prefix can be changed using the `help()` function on the command.
15
+ */
16
+ input: zod_1.default.string().optional(),
17
+ /**
18
+ * Output of the example. This will appear as a line below the input, with a `>` prefix.
19
+ * The prefix can be changed using the `help()` function on the command.
20
+ */
21
+ output: zod_1.default.string().optional(),
22
+ });
23
+ class MassargExample {
24
+ constructor(config) {
25
+ exports.ExampleConfig.parse(config);
26
+ if (config.description === undefined &&
27
+ config.input === undefined &&
28
+ config.output === undefined) {
29
+ throw new error_1.ValidationError({
30
+ code: 'invalid_example',
31
+ message: 'Example must have at least one of description, input, or output',
32
+ path: ['example'],
33
+ });
34
+ }
35
+ this.description = config.description;
36
+ this.input = config.input;
37
+ this.output = config.output;
38
+ }
39
+ }
40
+ exports.MassargExample = MassargExample;
41
+ //# sourceMappingURL=example.js.map
package/example.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AACnB,mCAAyC;AAE5B,QAAA,aAAa,GAAG,aAAC,CAAC,MAAM,CAAC;IACpC,8FAA8F;IAC9F,WAAW,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC;;;OAGG;IACH,KAAK,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B;;;OAGG;IACH,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAA;AAGF,MAAa,cAAc;IAKzB,YAAY,MAAqB;QAC/B,qBAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC3B,IACE,MAAM,CAAC,WAAW,KAAK,SAAS;YAChC,MAAM,CAAC,KAAK,KAAK,SAAS;YAC1B,MAAM,CAAC,MAAM,KAAK,SAAS,EAC3B;YACA,MAAM,IAAI,uBAAe,CAAC;gBACxB,IAAI,EAAE,iBAAiB;gBACvB,OAAO,EAAE,iEAAiE;gBAC1E,IAAI,EAAE,CAAC,SAAS,CAAC;aAClB,CAAC,CAAA;SACH;QACD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;QACrC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;IAC7B,CAAC;CACF;AAtBD,wCAsBC"}