rcoli 0.6.8 → 0.7.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/rcoli/model.rb +19 -17
- data/lib/rcoli/utils.rb +2 -0
- data/lib/rcoli/version.rb +1 -1
- data/lib/rcoli.rb +1 -1
- data/rcoli.gemspec +3 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 921fb46c2cbd5497b9113de61d816a0042449050
|
4
|
+
data.tar.gz: dfdac228b77b754dc6bcf77d06ab8573b5f81ab0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c72236617c59c39fc9dd25fbdc601a4f41a0ed0c0437066922064c1d4c2fbe24137e195dd168373e6160db71f0b99696d5c3dc35438980660d07797be09face
|
7
|
+
data.tar.gz: 19f9d4500577edb50b0985f100d768058159f50300262d2c81a6926a321ef8e81e23c0218670f707cf35b1d85e3ba8549edd3e0ac84e15f5b99c47661e139528
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -30,14 +30,14 @@ Library for development of command line applications in Ruby.
|
|
30
30
|
c.description "Commands for creating and managing nodes"
|
31
31
|
c.command :create do |sc|
|
32
32
|
sc.description "Creates node"
|
33
|
-
sc.action do |
|
33
|
+
sc.action do |opts, args|
|
34
34
|
# your action here
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
c.command :remove do |sc|
|
39
39
|
sc.description "Remove node"
|
40
|
-
sc.action do |
|
40
|
+
sc.action do |opts, args|
|
41
41
|
# your action here
|
42
42
|
end
|
43
43
|
end
|
data/lib/rcoli/model.rb
CHANGED
@@ -60,8 +60,7 @@ module RCoLi
|
|
60
60
|
else
|
61
61
|
value = true
|
62
62
|
end
|
63
|
-
|
64
|
-
option.keys.each{|key| result.send(target)[key] = value}
|
63
|
+
option.keys.each{|key| result.options[key] = value}
|
65
64
|
else
|
66
65
|
raise InvalidCommand, "'#{arg}' is not a valid option"
|
67
66
|
end
|
@@ -70,7 +69,7 @@ module RCoLi
|
|
70
69
|
result.command = cmd
|
71
70
|
cmd.put_default_values(result)
|
72
71
|
cmd.parse_args(args, result)
|
73
|
-
cmd.validate_options(result
|
72
|
+
cmd.validate_options(result)
|
74
73
|
elsif (commands.empty?)
|
75
74
|
result.arguments << arg
|
76
75
|
else
|
@@ -82,8 +81,7 @@ module RCoLi
|
|
82
81
|
|
83
82
|
def put_default_values(result)
|
84
83
|
options.find_all{|option| option.respond_to? :value_of_default_value and option.value_of_default_value}.each do |option|
|
85
|
-
|
86
|
-
option.keys.each{|key| result.send(target)[key] = option.value_of_default_value}
|
84
|
+
option.keys.each{|key| result.options[key] = option.value_of_default_value}
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
@@ -92,12 +90,12 @@ module RCoLi
|
|
92
90
|
return result
|
93
91
|
end
|
94
92
|
|
95
|
-
def validate_options(result
|
93
|
+
def validate_options(result)
|
96
94
|
if (result.command.nil? or result.command.value_of_force == true)
|
97
95
|
return
|
98
96
|
else
|
99
97
|
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.
|
98
|
+
raise InvalidCommand, "Required option '#{o.to_s}' is missing" unless o.keys.find{|key| result.options[key]}
|
101
99
|
end
|
102
100
|
end
|
103
101
|
end
|
@@ -105,7 +103,13 @@ module RCoLi
|
|
105
103
|
private
|
106
104
|
|
107
105
|
def find_option(name)
|
108
|
-
|
106
|
+
all_options = []
|
107
|
+
command = self
|
108
|
+
begin
|
109
|
+
all_options.concat(command.options)
|
110
|
+
command = command.parent
|
111
|
+
end while(command)
|
112
|
+
all_options.find{|opt| opt.correspond?(name)}
|
109
113
|
end
|
110
114
|
|
111
115
|
def is_option?(value)
|
@@ -201,7 +205,7 @@ module RCoLi
|
|
201
205
|
result = ParsedArgs.new
|
202
206
|
put_default_values(result)
|
203
207
|
parse_args(args, result)
|
204
|
-
validate_options(result
|
208
|
+
validate_options(result)
|
205
209
|
if result.command
|
206
210
|
|
207
211
|
# command has to have the action block
|
@@ -209,23 +213,23 @@ module RCoLi
|
|
209
213
|
raise ApplicationError, "Invalid configuration. Missing action block." unless action
|
210
214
|
|
211
215
|
# enable/disable logging level DEBUG
|
212
|
-
if (result.
|
216
|
+
if (result.options['debug'])
|
213
217
|
context.instance_exec do
|
214
218
|
log.level = Logger::DEBUG
|
215
219
|
end
|
216
220
|
end
|
217
221
|
|
218
222
|
# enable dev mode
|
219
|
-
if (result.
|
223
|
+
if (result.options['dev-mode'])
|
220
224
|
ApplicationContext.instance.devmode = true
|
221
225
|
end
|
222
226
|
|
223
227
|
# execution of the pre block
|
224
|
-
context.instance_exec(result.
|
228
|
+
context.instance_exec(result.options, result.arguments, &@pre_action) if (@pre_action and !result.command.value_of_skip_pre)
|
225
229
|
# execution of the main block
|
226
|
-
context.instance_exec(result.
|
230
|
+
context.instance_exec(result.options, result.arguments, &action)
|
227
231
|
# execution of the post block
|
228
|
-
context.instance_exec(result.
|
232
|
+
context.instance_exec(result.options, result.arguments, &@post_action) if (@post_action and !result.command.value_of_skip_post)
|
229
233
|
else
|
230
234
|
say "This feature is comming soon. You should execute '#{value_of_name} help' now."
|
231
235
|
end
|
@@ -244,14 +248,12 @@ module RCoLi
|
|
244
248
|
|
245
249
|
class ParsedArgs
|
246
250
|
|
247
|
-
|
248
|
-
attr_reader :options
|
251
|
+
attr_accessor :options
|
249
252
|
attr_reader :arguments
|
250
253
|
|
251
254
|
attr_accessor :command
|
252
255
|
|
253
256
|
def initialize
|
254
|
-
@global_options = {}
|
255
257
|
@options = {}
|
256
258
|
@arguments = []
|
257
259
|
end
|
data/lib/rcoli/utils.rb
CHANGED
data/lib/rcoli/version.rb
CHANGED
data/lib/rcoli.rb
CHANGED
data/rcoli.gemspec
CHANGED
@@ -5,11 +5,12 @@ require "rcoli/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "rcoli"
|
7
7
|
s.version = RCoLi::VERSION
|
8
|
-
s.authors = ["Jiri Pisa"]
|
9
|
-
s.email = ["jirka.pisa@gmail.com"]
|
8
|
+
s.authors = ["Jiri Pisa", "Jaroslav Barton"]
|
9
|
+
s.email = ["jirka.pisa@gmail.com", "jaroslav@bartonovi.eu"]
|
10
10
|
s.homepage = "https://github.com/jiripisa/rcoli"
|
11
11
|
s.summary = "The complete solution for commandline application written in ruby."
|
12
12
|
s.description = "The complete solution for commandline application written in ruby."
|
13
|
+
s.licenses = ["MIT"]
|
13
14
|
|
14
15
|
s.files = `git ls-files`.split("\n")
|
15
16
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcoli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jiri Pisa
|
8
|
+
- Jaroslav Barton
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: highline
|
@@ -55,6 +56,7 @@ dependencies:
|
|
55
56
|
description: The complete solution for commandline application written in ruby.
|
56
57
|
email:
|
57
58
|
- jirka.pisa@gmail.com
|
59
|
+
- jaroslav@bartonovi.eu
|
58
60
|
executables: []
|
59
61
|
extensions: []
|
60
62
|
extra_rdoc_files: []
|
@@ -74,7 +76,8 @@ files:
|
|
74
76
|
- lib/rcoli/version.rb
|
75
77
|
- rcoli.gemspec
|
76
78
|
homepage: https://github.com/jiripisa/rcoli
|
77
|
-
licenses:
|
79
|
+
licenses:
|
80
|
+
- MIT
|
78
81
|
metadata: {}
|
79
82
|
post_install_message:
|
80
83
|
rdoc_options: []
|
@@ -92,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
95
|
version: '0'
|
93
96
|
requirements: []
|
94
97
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.0.
|
98
|
+
rubygems_version: 2.0.6
|
96
99
|
signing_key:
|
97
100
|
specification_version: 4
|
98
101
|
summary: The complete solution for commandline application written in ruby.
|