Returns a clone of this CommandArgumentSpec
Defines a flag (like -h
or --help
) for your Command's arguments
specification.
If given an identifier, it may be a single character or a long identifier. If given an optional long identifier in the options object parameter in addition to the identifier as the first parameter, the first paramater identifier may only be a single character. Example:
<Command>.arguments.defineFlag('f');
<Command>.arguments.defineFlag('bar');
<Command>.arguments.defineFlag('b', { long: 'baz' });
NOTE: If a flag is found and the parsing strategy is not set to
Advanced
(2
) then it will be treated as an operand
The identifier of the argument this argument should bind to. Arguments that are bound to another will fill that argument's value with theirs in the event that that argument has no value
<Command>.arguments.defineOperand('A', 'String', { bindTo: 'B' }); <Command>.arguments.defineOption('B', 'String')
In the above example, argument
A
is bound to argumentB
. Whenever a value is passed forA
(a positional operand in this case), that value will be mirrored to argumentB
, provided argumentB
's value is undefined
A long-identifier for this Option (to be used like --long foo
)
Defines a positional operand argument declaration for your Command's arguments specification.
Must be given an identifier and a type, and can be declared required (true
by default).
Optional operands must be defined last and may not be followed by a non-optional operand.
May also be declared as a rest operand (false
by default), which will consume the remainder
of the input as a single operand when parsing for that operand begins. Rest operands must be
defined last and may not be followed by any additional operands.
Operand identifiers must be at least 2 characters to avoid confusion and avoid conflict with flags and options
Examples:
<Command>.arguments.defineOperand('foo', 'String');
<Command>.arguments.defineOperand('bar', 'String', { required: false });
NOTE: If the parsing strategy is set to AllowQuoting
(1
) or higher
and a quoted operand is going to be parsed but the spec says it should be a
rest argument then the quotes will be preserved in the operand value.
NOTE: Rest operands will supercede any other kind of argument when
parsing for that operand begins. If the parsing strategy is Advanced
(2
)
but the parser encounters something that would otherwise be parsed as a flag
or option it will still be parsed as part of the rest operand. Note this
is only the case when the parser is currently consuming a rest operand.
NOTE: If the parsing strategy is not set to Advanced
(2
) then
every argument encountered will be treated as an operand. If an argument
follows a flag and that flag is not defined as an Option via defineOption()
then the argument will be parsed as an operand and the flag will be parsed
as a flag as expected
The identifier of the argument this argument should bind to. Arguments that are bound to another will fill that argument's value with theirs in the event that that argument has no value
<Command>.arguments.defineOperand('A', 'String', { bindTo: 'B' }); <Command>.arguments.defineOption('B', 'String')
In the above example, argument
A
is bound to argumentB
. Whenever a value is passed forA
(a positional operand in this case), that value will be mirrored to argumentB
, provided argumentB
's value is undefined
Whether or not this operand is a required argument (Defaults to true
)
Whether or not this operand is a rest operand (Defaults to false
)
Defines an option that takes an argument (like -f value
) for your Command's arguments
specification.
If given an identifier, it may be a single character or a long identifier. If given an optional long identifier in the options object parameter in addition to the identifier as the first parameter, the first paramater may only be a single character. Examples:
<Command>.arguments.defineOption('f', 'String');
<Command>.arguments.defineOption('bar', 'String');
<Command>.arguments.defineOption('b', 'String', { long: 'baz' });
NOTE: If an option is found and the parsing strategy is not set to Advanced
(2
)
then it will be treated as an operand. If an argument that can be parsed as an option
is found in a Command's input but the option is not declared then it will be treated
as a long flag and the argument passed to it will be treated as an operand
The identifier of the argument this argument should bind to. Arguments that are bound to another will fill that argument's value with theirs in the event that that argument has no value
<Command>.arguments.defineOperand('A', 'String', { bindTo: 'B' }); <Command>.arguments.defineOption('B', 'String')
In the above example, argument
A
is bound to argumentB
. Whenever a value is passed forA
(a positional operand in this case), that value will be mirrored to argumentB
, provided argumentB
's value is undefined
A long-identifier for this Option (to be used like --long foo
or --long=foo
)
Whether or not this option is required (Defaults to false
)
Matches arguments to their bindings, erroring if the bound argument does not exist. This should be called before commands are allowed to be run
Returns a flag or option spec for the given identifier.
NOTE: Operand specs should be retrieved by shifting the operands array of a cloned spec.
WARNING: Be sure to only operate on cloned specs. We do not want to shift the operand specs out of the original specification
Sets the argument parsing strategy. Can be set to one of the following:
0 -> Basic. All words are counted as separate operands
1 -> AllowQuoting. Same as basic, but multiple arguments can be quoted
to create a single operand
2 -> Advanced. Includes basic and quoting, adds flags and options
with arguments
Examples:
Basic -> `foo bar baz`
AllowQuoting -> `foo "bar baz" boo`
Advanced -> `foo -b --bar --baz="boo far faz"`
NOTE: The default strategy is Basic
(0
). This is set per command, so
setting one command's argument spec parsing strategy to AllowQuoting
or
Advanced
will not affect any other commands. This can also be changed at any
time, so you can feasibly iterate over all commands at runtime and forcibly change
their parsing strategy (for example, to allow quoted arguments on a loaded command
from a plugin that you did not write). For example:
CommandModule.commands.get('foo').arguments.setParsingStrategy(1);
Generated using TypeDoc
Used for defining the specification for what a Command's given arguments should look like so the input parser can know how to parse the input given for a Command