optopus 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -0
- data/lib/optopus.rb +22 -9
- metadata +5 -5
data/README
CHANGED
@@ -37,6 +37,9 @@ gem install optopus
|
|
37
37
|
desc 'access timestamp'
|
38
38
|
option :timestamp, '-T', '--timestamp TIME', :type => Time, :required => true
|
39
39
|
|
40
|
+
desc 'resource record'
|
41
|
+
option :record, '-R', '--record RECORD', :type => Array, :multiple => true
|
42
|
+
|
40
43
|
# read yaml config file and overwrite options
|
41
44
|
config_file '-c', '--config-file FILE'
|
42
45
|
|
data/lib/optopus.rb
CHANGED
@@ -92,6 +92,10 @@ module Optopus
|
|
92
92
|
def ambiguous_argument
|
93
93
|
raise OptionParser::AmbiguousArgument.new(*@args)
|
94
94
|
end
|
95
|
+
|
96
|
+
def not_given
|
97
|
+
raise OptionParser::NotGiven.new(*@args)
|
98
|
+
end
|
95
99
|
end # CheckerContext
|
96
100
|
|
97
101
|
class Options
|
@@ -109,13 +113,13 @@ module Optopus
|
|
109
113
|
def release=(v) ; @parser.release = v ; end
|
110
114
|
|
111
115
|
def add(name, args, desc, block)
|
112
|
-
args, defval, required = fix_args(args, desc)
|
113
|
-
@opts_args << [name.to_sym, args, defval, block, required]
|
116
|
+
args, defval, required, multiple = fix_args(args, desc)
|
117
|
+
@opts_args << [name.to_sym, args, defval, block, required, multiple]
|
114
118
|
end
|
115
119
|
|
116
120
|
def add_file(args, desc)
|
117
121
|
raise 'two or more config_file is defined' if @file_args
|
118
|
-
args, defval, required = fix_args(args, desc)
|
122
|
+
args, defval, required, multiple = fix_args(args, desc)
|
119
123
|
@file_args = args
|
120
124
|
end
|
121
125
|
|
@@ -138,7 +142,7 @@ module Optopus
|
|
138
142
|
config = YAML.load_file(v)
|
139
143
|
options.instance_variable_set(:@__config_file__, config)
|
140
144
|
|
141
|
-
@opts_args.each do |name, args, defval, block, required|
|
145
|
+
@opts_args.each do |name, args, defval, block, required, multiple|
|
142
146
|
if args[1].kind_of?(String) and args[1] =~ /-+([^\s=]+)/
|
143
147
|
key = $1
|
144
148
|
else
|
@@ -158,20 +162,27 @@ module Optopus
|
|
158
162
|
end
|
159
163
|
|
160
164
|
value = conv.call(value) if conv
|
161
|
-
|
165
|
+
|
162
166
|
options[name] = value
|
163
167
|
end
|
164
168
|
end
|
165
169
|
end
|
166
170
|
|
167
|
-
@opts_args.each do |name, args, defval, block, required|
|
171
|
+
@opts_args.each do |name, args, defval, block, required, multiple|
|
168
172
|
options[name] = defval unless defval.nil?
|
169
173
|
has_arg_v = (args.first == '-v')
|
170
174
|
has_arg_h = (args.first == '-h')
|
171
175
|
|
172
176
|
@parser.on(*args) do |*v|
|
173
177
|
value = v.first || true
|
174
|
-
|
178
|
+
|
179
|
+
if multiple
|
180
|
+
options[name] ||= []
|
181
|
+
options[name] << value
|
182
|
+
else
|
183
|
+
options[name] = value
|
184
|
+
end
|
185
|
+
|
175
186
|
CheckerContext.evaluate(v, value, &block) if block
|
176
187
|
end
|
177
188
|
end
|
@@ -193,7 +204,7 @@ module Optopus
|
|
193
204
|
|
194
205
|
@parser.parse!
|
195
206
|
|
196
|
-
@opts_args.each do |name, args, defval, block, required|
|
207
|
+
@opts_args.each do |name, args, defval, block, required, multiple|
|
197
208
|
if required and not options.has_key?(name)
|
198
209
|
raise OptionParser::NotGiven, args.first
|
199
210
|
end
|
@@ -214,17 +225,19 @@ module Optopus
|
|
214
225
|
def fix_args(args, desc)
|
215
226
|
defval = nil
|
216
227
|
required = false
|
228
|
+
multiple = false
|
217
229
|
|
218
230
|
if args.last.kind_of?(Hash)
|
219
231
|
hash = args.pop
|
220
232
|
args = (args.slice(0, 2) + [hash[:type], hash[:desc] || desc]).select {|i| i }
|
221
233
|
defval = hash[:default]
|
222
234
|
required = hash[:required]
|
235
|
+
multiple = hash[:multiple]
|
223
236
|
elsif desc
|
224
237
|
args = args + [desc]
|
225
238
|
end
|
226
239
|
|
227
|
-
return [args, defval, required]
|
240
|
+
return [args, defval, required, multiple]
|
228
241
|
end
|
229
242
|
end # Options
|
230
243
|
end # Optopus
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optopus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- winebarrel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-06 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description:
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements: []
|
59
59
|
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.1
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: optopus is an easy-to-use option purser.
|