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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28273dca67c807b11bd81c7e7af01d750ae622e
4
- data.tar.gz: 1acd714ad5641350afbf5b691a16d7487ab5e066
3
+ metadata.gz: 921fb46c2cbd5497b9113de61d816a0042449050
4
+ data.tar.gz: dfdac228b77b754dc6bcf77d06ab8573b5f81ab0
5
5
  SHA512:
6
- metadata.gz: c6d196864e8620a1a1a9cb0d078e81733f4959a53ebc560d4c6919f91897557a663696a3dd19f3bc9430b444fc9ffcc27b306011f98bfc5851fb6a019b5624a2
7
- data.tar.gz: c1752f5405dd90ffff2ebecdd6d0a2c553ef25a812ba765d24153314f1d9bd2c81e34a7b95dcc57924bcb8f6d66232c7aa6d15ed7079abc3c24305c96554a98f
6
+ metadata.gz: 8c72236617c59c39fc9dd25fbdc601a4f41a0ed0c0437066922064c1d4c2fbe24137e195dd168373e6160db71f0b99696d5c3dc35438980660d07797be09face
7
+ data.tar.gz: 19f9d4500577edb50b0985f100d768058159f50300262d2c81a6926a321ef8e81e23c0218670f707cf35b1d85e3ba8549edd3e0ac84e15f5b99c47661e139528
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rcoli (0.6.4)
4
+ rcoli (0.7.0)
5
5
  highline (~> 1.6.11)
6
6
  paint (= 0.8.5)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- highline (1.6.15)
11
+ highline (1.6.20)
12
12
  paint (0.8.5)
13
13
  rake (10.0.3)
14
14
 
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 |global_opts, opts, args|
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 |global_opts, opts, args|
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
- target = self.parent ? :options : :global_options
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, :options)
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
- target = self.parent ? :options : :global_options
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, target)
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.send(target)[key]}
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
- options.find{|opt| opt.correspond?(name)}
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, :global_options)
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.global_options['debug'])
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.global_options['dev-mode'])
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.global_options, result.options, result.arguments, &@pre_action) if (@pre_action and !result.command.value_of_skip_pre)
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.global_options, result.options, result.arguments, &action)
230
+ context.instance_exec(result.options, result.arguments, &action)
227
231
  # execution of the post block
228
- context.instance_exec(result.global_options, result.options, result.arguments, &@post_action) if (@post_action and !result.command.value_of_skip_post)
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
- attr_reader :global_options
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
@@ -28,6 +28,8 @@ module RCoLi
28
28
  case severity
29
29
  when "DEBUG"
30
30
  color = 'gray27'
31
+ when "FATAL"
32
+ color = :red
31
33
  else
32
34
  color = :white
33
35
  end
data/lib/rcoli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RCoLi
2
2
 
3
- VERSION = '0.6.8'
3
+ VERSION = '0.7.0'
4
4
 
5
5
  end
data/lib/rcoli.rb CHANGED
@@ -23,7 +23,7 @@ def application(id, &block)
23
23
  c.skip_pre true
24
24
  c.skip_post true
25
25
  c.force true
26
- c.action do |global_opts, opts, args|
26
+ c.action do |opts, args|
27
27
  @program.help args
28
28
  end
29
29
  end
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.6.8
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: 2013-10-07 00:00:00.000000000 Z
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.7
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.