Skip to main content

Class: MassargFlag

option.MassargFlag

A boolean option that can be passed to a command.

A flag is an option that is either present or not. It can be used to toggle a boolean value, or to indicate that a command should be run in a different mode.

A flag can be negated by using negatable: true. By default, the negated name is the same as the option name, prefixed by no-, and each of the aliases will be uppercased. For example, --verbose and --no-verbose, or -v and -V. This behavior can be overridden by the negatedName and negatedAliases options.

Example

massarg.flag({
name: 'verbose',
aliases: ['v'],
description: 'Enable verbose logging',
defaultValue: false,
})

Hierarchy

Constructors

constructor

new MassargFlag(options): MassargFlag

Parameters

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

Returns

MassargFlag

Overrides

MassargOption.constructor

Defined in

src/option.ts:367

Properties

negatable

negatable: boolean

Whether this flag may be negated using negationName or negationAliases.

Defined in

src/option.ts:361


negationName

negationName: string

The negation name of this flag, which can be used with the full option notation.

Defined in

src/option.ts:363


negationAliases

negationAliases: string[]

The negation aliases of this flag, which can be used with the shorthand option notation.

Defined in

src/option.ts:365


name

name: string

Inherited from

MassargOption.name

Defined in

src/option.ts:177


description

description: string

Inherited from

MassargOption.description

Defined in

src/option.ts:178


defaultValue

Optional defaultValue: boolean

Inherited from

MassargOption.defaultValue

Defined in

src/option.ts:179


aliases

aliases: string[]

Inherited from

MassargOption.aliases

Defined in

src/option.ts:180


parse

parse: Parser<ArgsObject, boolean>

Inherited from

MassargOption.parse

Defined in

src/option.ts:181


isArray

isArray: boolean

Whether this option can be used multiple times. Any passed values will end up in an array instead of each usage overwriting the existing value.

Inherited from

MassargOption.isArray

Defined in

src/option.ts:186


isRequired

isRequired: boolean

Whether this option is required. Failing to specify this option will throw an error.

Inherited from

MassargOption.isRequired

Defined in

src/option.ts:188


isDefault

isDefault: boolean

Inherited from

MassargOption.isDefault

Defined in

src/option.ts:189


outputName

Optional outputName: string

Inherited from

MassargOption.outputName

Defined in

src/option.ts:190

Methods

fromTypedConfig

fromTypedConfig<T, A>(config): MassargOption<T, ArgsObject>

Create a typed option from a configuration. Currently supports number options which are automatically transformed from string to number.

Type parameters

NameType
Tunknown
Aextends ArgsObject = ArgsObject

Parameters

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

Returns

MassargOption<T, ArgsObject>

Inherited from

MassargOption.fromTypedConfig

Defined in

src/option.ts:209


parseDetails

parseDetails(argv, _options, prefixes): ArgvValue<boolean>

Parameters

NameType
argvstring[]
_optionsArgsObject
prefixesPrefixes

Returns

ArgvValue<boolean>

Overrides

MassargOption.parseDetails

Defined in

src/option.ts:377


qualifiedNames

qualifiedNames(prefixes): QualifiedNames

Return the finalized names that will cause this option to match.

Parameters

NameType
prefixesPrefixes

Returns

QualifiedNames

Overrides

MassargOption.qualifiedNames

Defined in

src/option.ts:418


getOutputName

getOutputName(): string

Returns the key which this option outputs to in the final object.

Returns

string

Default

The camelCase version of this option's name.

Can be overridden with {@link outputName}.

Inherited from

MassargOption.getOutputName

Defined in

src/option.ts:226


helpString

helpString(): string

Get the help string for this option

Returns

string

Inherited from

MassargOption.helpString

Defined in

src/option.ts:260


isMatch

isMatch(arg, prefixes): boolean

Returns true if the flag (including any prefixes) matches the name or aliases

Parameters

NameType
argstring
prefixesPrefixes

Returns

boolean

Inherited from

MassargOption.isMatch

Defined in

src/option.ts:266