rcoli 0.5.7 → 0.5.8
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/Gemfile.lock +1 -1
- data/lib/rcoli/extensions.rb +1 -1
- data/lib/rcoli/model.rb +30 -14
- data/lib/rcoli/version.rb +1 -1
- data/lib/rcoli.rb +3 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/rcoli/extensions.rb
CHANGED
data/lib/rcoli/model.rb
CHANGED
@@ -8,8 +8,12 @@ module RCoLi
|
|
8
8
|
|
9
9
|
module CommandContainer
|
10
10
|
|
11
|
+
setter :force
|
12
|
+
|
13
|
+
|
11
14
|
attr_accessor :parent
|
12
15
|
|
16
|
+
|
13
17
|
def action(&block)
|
14
18
|
@action = block
|
15
19
|
end
|
@@ -18,8 +22,8 @@ module RCoLi
|
|
18
22
|
@action
|
19
23
|
end
|
20
24
|
|
21
|
-
def command(
|
22
|
-
obj = Command.new(
|
25
|
+
def command(nam, &block)
|
26
|
+
obj = Command.new(nam)
|
23
27
|
obj.parent = self
|
24
28
|
block.call(obj)
|
25
29
|
commands << obj
|
@@ -66,6 +70,7 @@ module RCoLi
|
|
66
70
|
result.command = cmd
|
67
71
|
cmd.put_default_values(result)
|
68
72
|
cmd.parse_args(args, result)
|
73
|
+
cmd.validate_options(result, :options)
|
69
74
|
elsif (commands.empty?)
|
70
75
|
result.arguments << arg
|
71
76
|
else
|
@@ -83,7 +88,18 @@ module RCoLi
|
|
83
88
|
end
|
84
89
|
|
85
90
|
def find_command(name)
|
86
|
-
commands.find{|command| command.value_of_name.eql? name}
|
91
|
+
result = commands.find{|command| command.value_of_name.to_s.eql? name}
|
92
|
+
return result
|
93
|
+
end
|
94
|
+
|
95
|
+
def validate_options(result, target)
|
96
|
+
if (result.command.value_of_force == true)
|
97
|
+
return
|
98
|
+
else
|
99
|
+
self.options.find_all{|o| o.is_a? Flag and o.value_of_required}.each do |o|
|
100
|
+
raise InvalidCommand, "Required option '#{o.to_s}' is missing" unless o.keys.find{|key| result.send(target)[key]}
|
101
|
+
end
|
102
|
+
end
|
87
103
|
end
|
88
104
|
|
89
105
|
private
|
@@ -111,6 +127,10 @@ module RCoLi
|
|
111
127
|
[@s_name, @l_name].compact
|
112
128
|
end
|
113
129
|
|
130
|
+
def to_s
|
131
|
+
keys.join(', ')
|
132
|
+
end
|
133
|
+
|
114
134
|
def help_keys
|
115
135
|
result = []
|
116
136
|
result << "-#{@s_name}" if @s_name
|
@@ -136,6 +156,7 @@ module RCoLi
|
|
136
156
|
|
137
157
|
setter :default_value
|
138
158
|
setter :arg_name
|
159
|
+
setter :required
|
139
160
|
|
140
161
|
end
|
141
162
|
|
@@ -145,14 +166,8 @@ module RCoLi
|
|
145
166
|
setter :summary
|
146
167
|
setter :description
|
147
168
|
setter :syntax
|
148
|
-
|
149
|
-
|
150
|
-
@solitaire = true
|
151
|
-
end
|
152
|
-
|
153
|
-
def solitaire?
|
154
|
-
return true == @solitaire
|
155
|
-
end
|
169
|
+
setter :skip_pre
|
170
|
+
setter :skip_post
|
156
171
|
|
157
172
|
def initialize(name)
|
158
173
|
@name = name
|
@@ -186,11 +201,12 @@ module RCoLi
|
|
186
201
|
result = ParsedArgs.new
|
187
202
|
put_default_values(result)
|
188
203
|
parse_args(args, result)
|
204
|
+
validate_options(result, :global_options)
|
189
205
|
if result.command
|
190
206
|
|
191
207
|
# command has to have the action block
|
192
208
|
action = result.command.get_action
|
193
|
-
raise "Invalid configuration. Missing action block." unless action
|
209
|
+
raise ApplicationError, "Invalid configuration. Missing action block." unless action
|
194
210
|
|
195
211
|
# enable/disable logging level DEBUG
|
196
212
|
if (result.global_options['debug'])
|
@@ -200,11 +216,11 @@ module RCoLi
|
|
200
216
|
end
|
201
217
|
|
202
218
|
# execution of the pre block
|
203
|
-
context.instance_exec(result.global_options, result.options, result.arguments, &@pre_action) if (@pre_action and !result.command.
|
219
|
+
context.instance_exec(result.global_options, result.options, result.arguments, &@pre_action) if (@pre_action and !result.command.value_of_skip_pre)
|
204
220
|
# execution of the main block
|
205
221
|
context.instance_exec(result.global_options, result.options, result.arguments, &action)
|
206
222
|
# execution of the post block
|
207
|
-
context.instance_exec(result.global_options, result.options, result.arguments, &@post_action) if (@post_action and !result.command.
|
223
|
+
context.instance_exec(result.global_options, result.options, result.arguments, &@post_action) if (@post_action and !result.command.value_of_skip_post)
|
208
224
|
else
|
209
225
|
say "This feature is comming soon. Now you should execute '#{value_of_name} help'"
|
210
226
|
end
|
data/lib/rcoli/version.rb
CHANGED
data/lib/rcoli.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcoli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
segments:
|
80
80
|
- 0
|
81
|
-
hash:
|
81
|
+
hash: 2822556458840030411
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
segments:
|
89
89
|
- 0
|
90
|
-
hash:
|
90
|
+
hash: 2822556458840030411
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
93
|
rubygems_version: 1.8.24
|