optopus 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +9 -7
- data/lib/optopus.rb +7 -7
- metadata +3 -3
data/README
CHANGED
@@ -14,9 +14,8 @@ gem install optopus
|
|
14
14
|
require 'optopus'
|
15
15
|
|
16
16
|
opts = optopus do
|
17
|
-
desc 'program information'
|
18
|
-
|
19
|
-
|
17
|
+
option :info, '-I', :desc => 'program information'
|
18
|
+
|
20
19
|
desc 'print lots of debugging information'
|
21
20
|
option :debug, '-d', '--debug'
|
22
21
|
|
@@ -24,23 +23,26 @@ gem install optopus
|
|
24
23
|
option :output_file, '-o', '--output-file FILE', :default => '/var/log/xxx.log'
|
25
24
|
|
26
25
|
desc 'set number of retries to NUMBER (0 unlimits)'
|
27
|
-
option :tries, '-t', '--tries NUMBER', :type => Integer, :default => 0 do
|
26
|
+
option :tries, '-t', '--tries NUMBER', :type => Integer, :default => 0 do |value|
|
28
27
|
# custom validation
|
29
|
-
invalid_argument if
|
28
|
+
invalid_argument if value < 0
|
30
29
|
end
|
31
30
|
|
32
31
|
desc 'comma-separated list of accepted extensions'
|
33
32
|
option :accept, '-A', '--accept LIST', :type => Array, :default => []
|
34
33
|
|
34
|
+
desc 'access protocol'
|
35
|
+
option :protocol, '-P', '--protocol PROTO', :type => [:http, :ftp]
|
36
|
+
|
35
37
|
desc 'access timestamp'
|
36
38
|
option :timestamp, '-T', '--timestamp TIME', :type => Time
|
37
39
|
|
38
40
|
# read yaml config file and overwrite options
|
39
41
|
config_file '-c', '--config-file FILE'
|
40
42
|
|
41
|
-
after do
|
43
|
+
after do |options|
|
42
44
|
# postprocessing
|
43
|
-
#
|
45
|
+
# options.each { ... }
|
44
46
|
end
|
45
47
|
|
46
48
|
error do |e|
|
data/lib/optopus.rb
CHANGED
@@ -48,15 +48,15 @@ module Optopus
|
|
48
48
|
end # DefinerContext
|
49
49
|
|
50
50
|
class CheckerContext
|
51
|
-
def self.evaluate(args,
|
52
|
-
self.new(args,
|
51
|
+
def self.evaluate(args, pass, &block)
|
52
|
+
self.new(args, &block).evaluate(pass)
|
53
53
|
end
|
54
54
|
|
55
|
-
def initialize(value,
|
55
|
+
def initialize(value, &block)
|
56
56
|
@args = value ? [value] : []
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
if block
|
59
|
+
(class<<self; self; end).send(:define_method, :evaluate, &block)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -137,7 +137,7 @@ module Optopus
|
|
137
137
|
@parser.on(*args) do |*v|
|
138
138
|
value = v.first || true
|
139
139
|
options[name] = value
|
140
|
-
CheckerContext.evaluate(v,
|
140
|
+
CheckerContext.evaluate(v, value, &block) if block
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -187,7 +187,7 @@ module Optopus
|
|
187
187
|
end
|
188
188
|
|
189
189
|
@parser.parse!
|
190
|
-
CheckerContext.evaluate([],
|
190
|
+
CheckerContext.evaluate([], options, &@on_after) if @on_after
|
191
191
|
|
192
192
|
return options
|
193
193
|
rescue => e
|
metadata
CHANGED