Module: CLI::Kit::Args::Tokenizer
- Extended by:
- T::Sig
- Defined in:
- lib/cli/kit/args/tokenizer.rb
Defined Under Namespace
Classes: InvalidCharInShortOption, InvalidShortOption, Token
Constant Summary
collapse
- Error =
Class.new(Args::Error)
Class Method Summary
collapse
Methods included from T::Sig
sig
Class Method Details
.tokenize(raw_args) ⇒ Object
.tokenize_short_option(arg) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/cli/kit/args/tokenizer.rb', line 99
def tokenize_short_option(arg)
args = []
mode = :init
number = +''
arg.each_char do |char|
case mode
when :numeric
case char
when /[0-9]/
number << char
else
raise(InvalidShortOption, arg)
end
when :init
case char
when /[a-zA-Z]/
args << Token::ShortOptionName.new(char)
when /[0-9]/
mode = :numeric
number << char
else
raise(InvalidCharInShortOption.new(arg, char))
end
end
end
if number != ''
args << Token::OptionValue.new(number)
end
args
end
|