Class: Cuprum::Cli::Integrations::Thor::ArgumentsParser
- Inherits:
-
Object
- Object
- Cuprum::Cli::Integrations::Thor::ArgumentsParser
- Defined in:
- lib/cuprum/cli/integrations/thor/arguments_parser.rb
Overview
Utility for parsing command-line arguments captured by Thor tasks.
Any unrecognized command line flags or options are appended as-is to the arguments array by Thor. Therefore, to handle cases such as variadic options where flags or options cannot be pre-parsed by Thor, we need an additional parsing step to pull any remaining flags or options out of the arguments.
This parser supports the following formats:
-a,--all: Sets theaorallflag totrue.-abc: Sets thea,b, andcflags totrue.--skip-all,--no-all: Sets theaflag tofalse.-a=value,--a=value: Sets theaoption to"value".
The following formats are specifically not supported:
--foo bar:--foois assumed to be a flag,baris assumed to be a positional argument.--str[]=foo --str[]=bar: Array arguments are not supported.--str[foo]=foo --str[bar]=bar: Hash arguments are not supported.
In addition, parsed option values are coerced into their most likely intended types.
Instance Method Summary collapse
-
#call(*inputs) ⇒ Array<Array<String>, Hash{Symbol=>Object}>
Parses the given argument inputs into arguments and options.
Instance Method Details
#call(*inputs) ⇒ Array<Array<String>, Hash{Symbol=>Object}>
Parses the given argument inputs into arguments and options.
36 37 38 39 40 |
# File 'lib/cuprum/cli/integrations/thor/arguments_parser.rb', line 36 def call(*inputs) , arguments = inputs.partition { |str| str.start_with?('-') } [arguments, ()] end |