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
-
MassargOption<boolean>↳
MassargFlag
Constructors
constructor
• new MassargFlag(options): MassargFlag
Parameters
| Name | Type | Description |
|---|---|---|
options | Object | - |
options.name | string | Name of the option |
options.description | string | Description of the option, displayed in the help output |
options.aliases | string[] | Aliases for the option, which can be used with the shorthand option notation. |
options.defaultValue? | any | Default value of the option |
options.array? | boolean | Whether 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. |
options.required? | boolean | Whether the option is required. If it is required, parsing will throw an error if it's not present. |
options.hidden? | boolean | Whether the option is hidden. Hidden options are not displayed in the help output. |
options.outputName? | string | Specify a custom name for the output, which will be used when parsing the args. |
options.negatable? | boolean | Whether the flag can be negated, e.g. --no-verbose |
options.negationName? | string | Negation name of the option, which can be used with the full option notation. Defaults to no-{name} of your option's name, e.g. verbose becomes --no-verbose. To use this, you must set negatable: true in the option's configuration. |
options.negationAliases? | string[] | Negation aliases for the option, which can be used with the shorthand option notation. Defaults to uppercase of each of the aliases provided, e.g. q becomes -Q. To use this, you must set negatable: true in the option's configuration. |
Returns
Overrides
Defined in
Properties
negatable
• negatable: boolean
Whether this flag may be negated using negationName or negationAliases.
Defined in
negationName
• negationName: string
The negation name of this flag, which can be used with the full option notation.
Defined in
negationAliases
• negationAliases: string[]
The negation aliases of this flag, which can be used with the shorthand option notation.
Defined in
name
• name: string
Inherited from
Defined in
description
• description: string
Inherited from
Defined in
defaultValue
• Optional defaultValue: boolean
Inherited from
Defined in
aliases
• aliases: string[]
Inherited from
Defined in
parse
• parse: Parser<ArgsObject, boolean>
Inherited from
Defined in
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
Defined in
isRequired
• isRequired: boolean
Whether this option is required. Failing to specify this option will throw an error.
Inherited from
Defined in
isDefault
• isDefault: boolean
Inherited from
Defined in
outputName
• Optional outputName: string
Inherited from
Defined in
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
| Name | Type |
|---|---|
T | unknown |
A | extends ArgsObject = ArgsObject |
Parameters
| Name | Type | Description |
|---|---|---|
config | Object | - |
config.name | string | Name of the option |
config.description | string | Description of the option, displayed in the help output |
config.aliases | string[] | Aliases for the option, which can be used with the shorthand option notation. |
config.defaultValue? | any | Default value of the option |
config.parse? | Parser<A, T> | Parse the value of the option. You can return any type here, or throw an error if the value is invalid. |
config.array? | boolean | Whether 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. |
config.required? | boolean | Whether the option is required. If it is required, parsing will throw an error if it's not present. |
config.isDefault? | boolean | Whether 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. |
config.hidden? | boolean | Whether the option is hidden. Hidden options are not displayed in the help output. |
config.outputName? | string | Specify a custom name for the output, which will be used when parsing the args. |
config.type? | "number" | - |
Returns
Inherited from
Defined in
parseDetails
▸ parseDetails(argv, _options, prefixes): ArgvValue<boolean>
Parameters
| Name | Type |
|---|---|
argv | string[] |
_options | ArgsObject |
prefixes | Prefixes |
Returns
ArgvValue<boolean>
Overrides
MassargOption.parseDetails
Defined in
qualifiedNames
▸ qualifiedNames(prefixes): QualifiedNames
Return the finalized names that will cause this option to match.
Parameters
| Name | Type |
|---|---|
prefixes | Prefixes |
Returns
Overrides
Defined in
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
Defined in
helpString
▸ helpString(): string
Get the help string for this option
Returns
string
Inherited from
Defined in
isMatch
▸ isMatch(arg, prefixes): boolean
Returns true if the flag (including any prefixes) matches the name or aliases
Parameters
| Name | Type |
|---|---|
arg | string |
prefixes | Prefixes |
Returns
boolean