config_parser 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.5.1 / 2010-11-21
2
+
3
+ * added guessing of hints
4
+ * added brackets to argname for list help
5
+
1
6
  == 0.5.0 / 2010-11-21
2
7
 
3
8
  * yield argv and config to block on parse, if given
data/lib/config_parser.rb CHANGED
@@ -202,7 +202,6 @@ class ConfigParser
202
202
  attrs = args.last.kind_of?(Hash) ? args.pop : {}
203
203
  attrs = attrs.merge(:key => key, :default => default)
204
204
  args << attrs
205
-
206
205
  on(*args, &block)
207
206
  end
208
207
 
@@ -328,7 +327,10 @@ class ConfigParser
328
327
  def new_option(argv, &block) # :nodoc:
329
328
  attrs = argv.last.kind_of?(Hash) ? argv.pop : {}
330
329
  attrs = parse_attrs(argv).merge(attrs)
330
+
331
+ attrs[:hint] ||= guess_hint(attrs)
331
332
  attrs[:callback] = block if block
333
+
332
334
  option_class(attrs).new(attrs)
333
335
  end
334
336
  end
@@ -6,9 +6,6 @@ class ConfigParser
6
6
  # assigned to the same key.
7
7
  class List < Option
8
8
 
9
- # The default split character for multiple values
10
- DELIMITER = ','
11
-
12
9
  # The delimiter on which to split single values into multiple values; use
13
10
  # nil to prevent splitting.
14
11
  attr_reader :delimiter
@@ -55,5 +52,11 @@ class ConfigParser
55
52
  else [obj]
56
53
  end
57
54
  end
55
+
56
+ private
57
+
58
+ def header_str # :nodoc:
59
+ " #{short_str}#{long_str} [#{arg_name}]"
60
+ end
58
61
  end
59
62
  end
@@ -35,6 +35,9 @@ class ConfigParser
35
35
  #
36
36
  NEST = /\A--(.*):(.+)\z/
37
37
 
38
+ # The default split character for multiple values
39
+ DELIMITER = ','
40
+
38
41
  # Turns the input into a short flag by prefixing '-' (as needed). Raises
39
42
  # an error if the input doesn't result in a short flag. Nils are
40
43
  # returned directly.
@@ -162,7 +165,7 @@ class ConfigParser
162
165
  raise ArgumentError.new("invalid flag: #{arg.inspect}")
163
166
  end
164
167
  end
165
-
168
+
166
169
  attrs
167
170
  end
168
171
 
@@ -210,5 +213,18 @@ class ConfigParser
210
213
  else :option
211
214
  end
212
215
  end
216
+
217
+ def guess_hint(attrs)
218
+ default = attrs[:default]
219
+
220
+ case default
221
+ when true, false, nil
222
+ nil
223
+ when Array
224
+ default.join(attrs[:delimiter] || DELIMITER)
225
+ else
226
+ default.to_s
227
+ end
228
+ end
213
229
  end
214
230
  end
@@ -1,7 +1,7 @@
1
1
  class ConfigParser
2
2
  MAJOR = 0
3
3
  MINOR = 5
4
- TINY = 0
4
+ TINY = 1
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{TINY}"
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 0
10
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Chiang