optopus 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +2 -1
  2. data/lib/optopus.rb +15 -13
  3. metadata +4 -4
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == Description
4
4
 
5
- Enhanced option parser.
5
+ optopus is an easy-to-use option purser.
6
6
 
7
7
  == Install
8
8
 
@@ -51,3 +51,4 @@ gem install optopus
51
51
  end
52
52
 
53
53
  p opts
54
+ p opts.config_file
data/lib/optopus.rb CHANGED
@@ -131,22 +131,12 @@ module Optopus
131
131
  options = {}
132
132
  has_arg_v = false
133
133
  has_arg_h = false
134
-
135
- @opts_args.each do |name, args, defval, block, required|
136
- options[name] = defval unless defval.nil?
137
- has_arg_v = (args.first == '-v')
138
- has_arg_h = (args.first == '-h')
139
-
140
- @parser.on(*args) do |*v|
141
- value = v.first || true
142
- options[name] = value
143
- CheckerContext.evaluate(v, value, &block) if block
144
- end
145
- end
134
+ options.instance_eval("def config_file; @__config_file__; end")
146
135
 
147
136
  if @file_args
148
137
  @parser.on(*@file_args) do |v|
149
138
  config = YAML.load_file(v)
139
+ options.instance_variable_set(:@__config_file__, config)
150
140
 
151
141
  @opts_args.each do |name, args, defval, block, required|
152
142
  if args[1].kind_of?(String) and args[1] =~ /-+([^\s=]+)/
@@ -155,7 +145,7 @@ module Optopus
155
145
  key = name.to_s
156
146
  end
157
147
 
158
- value = config[key] || config[name.to_s]
148
+ value = config[key] || config[key.gsub(/[-_]/, '-')] || key.gsub(/[-_]/, '_')
159
149
 
160
150
  next unless value
161
151
 
@@ -174,6 +164,18 @@ module Optopus
174
164
  end
175
165
  end
176
166
 
167
+ @opts_args.each do |name, args, defval, block, required|
168
+ options[name] = defval unless defval.nil?
169
+ has_arg_v = (args.first == '-v')
170
+ has_arg_h = (args.first == '-h')
171
+
172
+ @parser.on(*args) do |*v|
173
+ value = v.first || true
174
+ options[name] = value
175
+ CheckerContext.evaluate(v, value, &block) if block
176
+ end
177
+ end
178
+
177
179
  unless has_arg_v
178
180
  @parser.on_tail('-v', '--version', 'show version') do
179
181
  v = @parser.ver or abort("#{@parser.program_name}: version unknown")
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: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
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-01 00:00:00 Z
18
+ date: 2011-11-03 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: