@@ -50,6 +50,9 @@ export type OptionConfig<T = unknown, Args extends ArgsObject = ArgsObject> = z.
5050 ReturnType < typeof OptionConfig < T , Args > >
5151>
5252
53+ /**
54+ * Configuration for a flag (boolean argument) that can be passed to a command.
55+ */
5356export const FlagConfig = OptionConfig < boolean > ( z . any ( ) )
5457 . omit ( { parse : true , isDefault : true } )
5558 . merge (
@@ -84,6 +87,7 @@ export type Parser<Args extends ArgsObject = ArgsObject, OptionType extends any
8487 y : Args ,
8588) => OptionType
8689
90+ /** {@link OptionConfig } with a specified value type */
8791export const TypedOptionConfig = < OptionType , Args extends ArgsObject = ArgsObject > (
8892 type : z . ZodType < OptionType > ,
8993) =>
@@ -117,7 +121,9 @@ export type ArrayOptionConfig<T = unknown> = z.infer<
117121 ReturnType < typeof ArrayOptionConfig < z . ZodType < T > > >
118122>
119123
124+ /** The default prefixes for options */
120125export const DEFAULT_OPT_FULL_PREFIX = '--'
126+ /** The default prefix for option aliases */
121127export const DEFAULT_OPT_SHORT_PREFIX = '-'
122128
123129/* Prefixes for options */
@@ -173,7 +179,12 @@ export class MassargOption<OptionType extends any = unknown, Args extends ArgsOb
173179 defaultValue ?: OptionType
174180 aliases : string [ ]
175181 parse : Parser < Args , OptionType >
182+ /**
183+ * Whether this option can be used multiple times. Any passed values will end up in an array
184+ * instead of each usage overwriting the existing value.
185+ */
176186 isArray : boolean
187+ /** Whether this option is required. Failing to specify this option will throw an error. */
177188 isRequired : boolean
178189 isDefault : boolean
179190 outputName ?: string
@@ -191,6 +202,10 @@ export class MassargOption<OptionType extends any = unknown, Args extends ArgsOb
191202 this . outputName = options . outputName
192203 }
193204
205+ /**
206+ * Create a typed option from a configuration. Currently supports `number` options which
207+ * are automatically transformed from `string` to `number`.
208+ */
194209 static fromTypedConfig < T = unknown , A extends ArgsObject = ArgsObject > (
195210 config : TypedOptionConfig < T , A > ,
196211 ) : MassargOption < T > {
@@ -201,10 +216,18 @@ export class MassargOption<OptionType extends any = unknown, Args extends ArgsOb
201216 return new MassargOption ( config as OptionConfig < T > )
202217 }
203218
219+ /**
220+ * Returns the key which this option outputs to in the final object.
221+ *
222+ * @default The camelCase version of this option's name.
223+ *
224+ * Can be overridden with {@link outputName}.
225+ */
204226 getOutputName ( ) : string {
205227 return this . outputName || toCamelCase ( this . name )
206228 }
207229
230+ /** @internal */
208231 parseDetails ( argv : string [ ] , options : ArgsObject , prefixes : Prefixes ) : ArgvValue < OptionType > {
209232 let input = ''
210233 try {
@@ -233,6 +256,7 @@ export class MassargOption<OptionType extends any = unknown, Args extends ArgsOb
233256 }
234257 }
235258
259+ /** Get the help string for this option */
236260 helpString ( ) : string {
237261 const aliases = this . aliases . length ? `|${ this . aliases . join ( '|-' ) } ` : ''
238262 return `--${ this . name } ${ aliases } ${ this . description } `
@@ -249,6 +273,7 @@ export class MassargOption<OptionType extends any = unknown, Args extends ArgsOb
249273 )
250274 }
251275
276+ /** Return the finalized names that will cause this option to match. */
252277 qualifiedNames ( prefixes : Prefixes ) : QualifiedNames {
253278 return {
254279 name : prefixes . normalPrefix + this . name ,
@@ -310,7 +335,7 @@ export class MassargNumber extends MassargOption<number> {
310335}
311336
312337/**
313- * An option that can be passed to a command.
338+ * A boolean option that can be passed to a command.
314339 *
315340 * A flag is an option that is either present or not. It can be used to toggle
316341 * a boolean value, or to indicate that a command should be run in a different
@@ -332,8 +357,11 @@ export class MassargNumber extends MassargOption<number> {
332357 * ```
333358 */
334359export class MassargFlag extends MassargOption < boolean > {
360+ /** Whether this flag may be negated using `negationName` or `negationAliases`. */
335361 negatable : boolean
362+ /** The negation name of this flag, which can be used with the full option notation. */
336363 negationName : string
364+ /** The negation aliases of this flag, which can be used with the shorthand option notation. */
337365 negationAliases : string [ ]
338366
339367 constructor ( options : FlagConfig ) {
@@ -396,6 +424,7 @@ export class MassargFlag extends MassargOption<boolean> {
396424 }
397425}
398426
427+ /** A flag that can be passed to a command to show the help message. */
399428export class MassargHelpFlag extends MassargFlag {
400429 constructor ( config : Partial < Omit < OptionConfig < boolean > , 'parse' > > = { } ) {
401430 super ( {
0 commit comments