argparser 2.0.1 → 2.1.1

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: b9c717835823cf29218ab1893f167714943d00ec
4
- data.tar.gz: c12e9a7624dc121e0ce1fcf0d708eaa875300fd7
3
+ metadata.gz: d01077ced5f014ee8a59a83db58de5185117f91e
4
+ data.tar.gz: 5011acf2b08ed536be20f8ab382c8bd4f65418e3
5
5
  SHA512:
6
- metadata.gz: 21606aa348b874c05a4ac882e5c0f78ba7f60634bcd7b275fb4367a125e10a8dd933cc7c18a335e6ea19c82128c37c059ae22e0e8c7bc4ad317e2c1b02b09cc0
7
- data.tar.gz: 8be8cce50bd10f549916e33d78b0075a2a23a94db83cf63ff9c048be37da3f1134962c5fd82c578547ca93d1392a2920ceccb24a0321500a78193c13d77e6676
6
+ metadata.gz: 9669ee8f4bff2d04795e2a148e54ef60cc58f30553633a79584646675616e11fb0e87fde5d9138afbe00dcc33b838a478b0bb5c6c9fe7a9e01e1512e05d20e3e
7
+ data.tar.gz: 7fb01f1d230f7ea3e5947b09276b034aaf755af30f78882ffbaa2fdfc459ed2c669362f0bea0c8be26c53068ead7f83a17fdf29a907f1f2c2a0dccc44cf3d3a8
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 2.1.1
2
+ 2015-08-17 Compatible
3
+
4
+ * makes gem backward compatible with 1.0
5
+
1
6
  # 2.0.1
2
7
  2015-04-28
3
8
 
@@ -73,10 +73,23 @@ class ArgParser
73
73
 
74
74
  def initialize(manifest)
75
75
  hash2vars(ArgParser.manifest.merge(manifest))
76
- @arguments =
77
- (@arguments || []).map {|o| o.kind_of?(Argument) ? o : Argument.new(o)}
78
- @options =
79
- (@options || []).map {|o| o.kind_of?(Option) ? o : Option.new(o)}
76
+ @arguments ||= []
77
+ @options ||= []
78
+ @options = @options.map do |o|
79
+ if o.kind_of?(Option)
80
+ o
81
+ else
82
+ if o['input'] || o[:input]
83
+ o[:name] ||= o['names'] || o[:names]
84
+ @arguments << o
85
+ nil
86
+ else
87
+ o[:param] ||= (o['argument'] || o[:argument])
88
+ Option.new(o)
89
+ end
90
+ end
91
+ end.compact
92
+ @arguments = @arguments.map {|o| o.kind_of?(Argument) ? o : Argument.new(o)}
80
93
  _check_manifest
81
94
  end
82
95
 
@@ -121,6 +134,8 @@ class ArgParser
121
134
  self
122
135
  end
123
136
 
137
+ alias parse! parse
138
+
124
139
  def terminate(code, str)
125
140
  s = StringIO.new
126
141
  s.puts(printed_synopsis) if code != 0
@@ -199,14 +214,14 @@ class ArgParser
199
214
  def _set_long_option(a, tail)
200
215
  terminate(2, TRM_UNKNOWN % a) unless a.size > 1 && (o = get_option(a))
201
216
  terminate(2, TRM_OPTION_ARGUMENT_EXPECTED % a) if o.param && tail.empty?
202
- o.add_value(o.param ? tail.shift : nil)
217
+ o.add_value(o.param ? tail.shift : true)
203
218
  end
204
219
 
205
220
  def _set_short_options(a, tail)
206
221
  a.chars.each_with_index do |char, index|
207
222
  terminate(2, TRM_UNKNOWN % char) unless (option = get_option(char))
208
223
  if !option.param
209
- option.add_value(nil)
224
+ option.add_value(true)
210
225
  elsif a.size-1 == index
211
226
  terminate(2, TRM_OPTION_ARGUMENT_EXPECTED % char) if tail.empty?
212
227
  option.add_value(tail.shift)
@@ -47,6 +47,11 @@ class ArgParser
47
47
  @count > 0
48
48
  end
49
49
 
50
+ def value=(new_value)
51
+ reset
52
+ Array(new_value).each {|nv| add_value(nv)}
53
+ end
54
+
50
55
  # Returns value as string
51
56
  def to_s
52
57
  multiple ? value.map(&:to_s).join(', ') : value.to_s
@@ -8,6 +8,9 @@ class ArgParser
8
8
  def name
9
9
  @name ||= names.first
10
10
  end
11
+
12
+ alias argument param
13
+
11
14
  # Names of an option (short, long, etc.)
12
15
  def names
13
16
  @names ||= [@name]
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  class ArgParser
4
- VERSION = '2.0.1'
4
+ VERSION = '2.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-28 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler