Skip to main content

Module: option

Classes

Type Aliases

OptionConfig

Ƭ OptionConfig<T, Args>: Object

Type parameters

NameType
Tunknown
Argsextends ArgsObject = ArgsObject

Type declaration

NameTypeDescription
namestringName of the option
descriptionstringDescription of the option, displayed in the help output
aliasesstring[]Aliases for the option, which can be used with the shorthand option notation.
defaultValue?anyDefault value of the option
array?booleanWhether the option is an array. Array options can be specified multiple times, and the values will be collected into an array. Normally, specifying an option multiple times will override the previous value.
required?booleanWhether the option is required. If it is required, parsing will throw an error if it's not present.
isDefault?booleanWhether the option is the default option. The default option is the option that is used if no other option is specified, e.g. a value is passed in without an option name. Note that if commands match the same argument first, they will be used instead of the default option.
hidden?booleanWhether the option is hidden. Hidden options are not displayed in the help output.
outputName?stringSpecify a custom name for the output, which will be used when parsing the args.
parse?Parser<Args, T>Parse the value of the option. You can return any type here, or throw an error if the value is invalid.

Defined in

src/option.ts:6

src/option.ts:49


FlagConfig

Ƭ FlagConfig: Object

Type declaration

NameType
namestring
descriptionstring
aliasesstring[]
defaultValueany
arrayundefined | boolean
requiredundefined | boolean
hiddenundefined | boolean
outputNameundefined | string
negatableundefined | boolean
negationNameundefined | string
negationAliasesundefined | string[]

Defined in

src/option.ts:56

src/option.ts:80


Parser

Ƭ Parser<Args, OptionType>: (x: string, y: Args) => OptionType

A function that parses an option value.

Type parameters

NameType
Argsextends ArgsObject = ArgsObject
OptionTypeextends any = any

Type declaration

▸ (x, y): OptionType

Parameters
NameType
xstring
yArgs
Returns

OptionType

Defined in

src/option.ts:85


TypedOptionConfig

Ƭ TypedOptionConfig<T, A>: Object

Type parameters

NameType
TT
Aextends ArgsObject = ArgsObject

Type declaration

NameType
namestring
descriptionstring
aliasesstring[]
typeundefined | "number"
defaultValueany
arrayundefined | boolean
requiredundefined | boolean
isDefaultundefined | boolean
hiddenundefined | boolean
outputNameundefined | string
parseundefined | Parser<A, T>

Defined in

src/option.ts:91

src/option.ts:99


ArrayOptionConfig

Ƭ ArrayOptionConfig<T>: Object

An option that can be passed to a command.

This type represents an array option, which can be specified multiple times.

Type parameters

NameType
Tunknown

Type declaration

NameType
namestring
descriptionstring
aliasesstring[]
typeundefined | "number"
defaultValueundefined | ZodType<T, ZodTypeDef, T>[]
arrayundefined | boolean
requiredundefined | boolean
isDefaultundefined | boolean
hiddenundefined | boolean
outputNameundefined | string
parseundefined | Parser<ArgsObject, ZodType<T, ZodTypeDef, T>[]>

Defined in

src/option.ts:107

src/option.ts:120


Prefixes

Ƭ Prefixes: Object

Type declaration

NameType
normalPrefixstring
aliasPrefixstring

Defined in

src/option.ts:130


Names

Ƭ Names: Object

Type declaration

NameType
namestring
aliasesstring[]

Defined in

src/option.ts:136


QualifiedNames

Ƭ QualifiedNames: Object

Names with prefixes built-in

Type declaration

NameType
namestring
aliasesstring[]
negationNamestring
negationAliasesstring[]

Defined in

src/option.ts:142

Variables

FlagConfig

Const FlagConfig: ZodObject<FlagConfig>

Configuration for a flag (boolean argument) that can be passed to a command.

Defined in

src/option.ts:56

src/option.ts:80


DEFAULT_OPT_FULL_PREFIX

Const DEFAULT_OPT_FULL_PREFIX: "--"

The default prefixes for options

Defined in

src/option.ts:125


DEFAULT_OPT_SHORT_PREFIX

Const DEFAULT_OPT_SHORT_PREFIX: "-"

The default prefix for option aliases

Defined in

src/option.ts:127

Functions

OptionConfig

OptionConfig<OptionType, Args>(type): ZodObject<{ name: ZodString ; description: ZodString ; defaultValue: ZodOptional<ZodAny> ; aliases: ZodArray<ZodString, "many"> ; parse: ZodOptional<ZodType<Parser<Args, OptionType>, ZodTypeDef, Parser<Args, OptionType>>> ; array: ZodOptional<ZodBoolean> ; required: ZodOptional<ZodBoolean> ; isDefault: ZodOptional<ZodBoolean> ; hidden: ZodOptional<ZodBoolean> ; outputName: ZodOptional<ZodString> }, "strip", ZodTypeAny, { name: string ; description: string ; aliases: string[] ; defaultValue?: any ; array?: boolean ; required?: boolean ; isDefault?: boolean ; hidden?: boolean ; outputName?: string ; parse?: Parser<Args, OptionType> }, { name: string ; description: string ; aliases: string[] ; defaultValue?: any ; array?: boolean ; required?: boolean ; isDefault?: boolean ; hidden?: boolean ; outputName?: string ; parse?: Parser<Args, OptionType> }>

Type parameters

NameType
OptionTypeOptionType
Argsextends ArgsObject = ArgsObject

Parameters

NameType
typeZodType<OptionType, ZodTypeDef, OptionType>

Returns

ZodObject<{ name: ZodString ; description: ZodString ; defaultValue: ZodOptional<ZodAny> ; aliases: ZodArray<ZodString, "many"> ; parse: ZodOptional<ZodType<Parser<Args, OptionType>, ZodTypeDef, Parser<Args, OptionType>>> ; array: ZodOptional<ZodBoolean> ; required: ZodOptional<ZodBoolean> ; isDefault: ZodOptional<ZodBoolean> ; hidden: ZodOptional<ZodBoolean> ; outputName: ZodOptional<ZodString> }, "strip", ZodTypeAny, { name: string ; description: string ; aliases: string[] ; defaultValue?: any ; array?: boolean ; required?: boolean ; isDefault?: boolean ; hidden?: boolean ; outputName?: string ; parse?: Parser<Args, OptionType> }, { name: string ; description: string ; aliases: string[] ; defaultValue?: any ; array?: boolean ; required?: boolean ; isDefault?: boolean ; hidden?: boolean ; outputName?: string ; parse?: Parser<Args, OptionType> }>

Defined in

src/option.ts:6


TypedOptionConfig

TypedOptionConfig<OptionType, Args>(type): ZodObject<extendShape<{ name: ZodString ; description: ZodString ; defaultValue: ZodOptional<ZodAny> ; aliases: ZodArray<ZodString, "many"> ; parse: ZodOptional<ZodType<Parser<Args, OptionType>, ZodTypeDef, Parser<Args, OptionType>>> ; array: ZodOptional<ZodBoolean> ; required: ZodOptional<ZodBoolean> ; isDefault: ZodOptional<ZodBoolean> ; hidden: ZodOptional<ZodBoolean> ; outputName: ZodOptional<ZodString> }, { type: ZodOptional<ZodEnum<["number"]>> }>, "strip", ZodTypeAny, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: any ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<Args, OptionType> }, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: any ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<Args, OptionType> }>

OptionConfig with a specified value type

Type parameters

NameType
OptionTypeOptionType
Argsextends ArgsObject = ArgsObject

Parameters

NameType
typeZodType<OptionType, ZodTypeDef, OptionType>

Returns

ZodObject<extendShape<{ name: ZodString ; description: ZodString ; defaultValue: ZodOptional<ZodAny> ; aliases: ZodArray<ZodString, "many"> ; parse: ZodOptional<ZodType<Parser<Args, OptionType>, ZodTypeDef, Parser<Args, OptionType>>> ; array: ZodOptional<ZodBoolean> ; required: ZodOptional<ZodBoolean> ; isDefault: ZodOptional<ZodBoolean> ; hidden: ZodOptional<ZodBoolean> ; outputName: ZodOptional<ZodString> }, { type: ZodOptional<ZodEnum<["number"]>> }>, "strip", ZodTypeAny, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: any ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<Args, OptionType> }, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: any ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<Args, OptionType> }>

Defined in

src/option.ts:91


ArrayOptionConfig

ArrayOptionConfig<T, A>(type): ZodObject<extendShape<extendShape<{ name: ZodString ; description: ZodString ; defaultValue: ZodOptional<ZodAny> ; aliases: ZodArray<ZodString, "many"> ; parse: ZodOptional<ZodType<Parser<A, T[]>, ZodTypeDef, Parser<A, T[]>>> ; array: ZodOptional<ZodBoolean> ; required: ZodOptional<ZodBoolean> ; isDefault: ZodOptional<ZodBoolean> ; hidden: ZodOptional<ZodBoolean> ; outputName: ZodOptional<ZodString> }, { type: ZodOptional<ZodEnum<["number"]>> }>, { defaultValue: ZodOptional<ZodArray<ZodType<T, ZodTypeDef, T>, "many">> }>, "strip", ZodTypeAny, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: undefined | T[] ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<A, T[]> }, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: undefined | T[] ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<A, T[]> }>

Type parameters

NameType
TT
Aextends ArgsObject = ArgsObject

Parameters

NameType
typeZodType<T, ZodTypeDef, T>

Returns

ZodObject<extendShape<extendShape<{ name: ZodString ; description: ZodString ; defaultValue: ZodOptional<ZodAny> ; aliases: ZodArray<ZodString, "many"> ; parse: ZodOptional<ZodType<Parser<A, T[]>, ZodTypeDef, Parser<A, T[]>>> ; array: ZodOptional<ZodBoolean> ; required: ZodOptional<ZodBoolean> ; isDefault: ZodOptional<ZodBoolean> ; hidden: ZodOptional<ZodBoolean> ; outputName: ZodOptional<ZodString> }, { type: ZodOptional<ZodEnum<["number"]>> }>, { defaultValue: ZodOptional<ZodArray<ZodType<T, ZodTypeDef, T>, "many">> }>, "strip", ZodTypeAny, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: undefined | T[] ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<A, T[]> }, { name: string ; description: string ; aliases: string[] ; type: undefined | "number" ; defaultValue: undefined | T[] ; array: undefined | boolean ; required: undefined | boolean ; isDefault: undefined | boolean ; hidden: undefined | boolean ; outputName: undefined | string ; parse: undefined | Parser<A, T[]> }>

See

  • OptionConfig
  • ArrayOptionConfig

Defined in

src/option.ts:107