optbind 0.0.2 → 0.1.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: 08d6fbf553b3406e305a2b8f2f238d322af9f940
4
- data.tar.gz: 6bbb9c352093c33304bf7efd1b9e28b58f4fae89
3
+ metadata.gz: 4469bc21ab4953923de07a629997c6594b7c1467
4
+ data.tar.gz: 744cb5fe0bc9999eb640a1649c6037aa9349d3cc
5
5
  SHA512:
6
- metadata.gz: d836778a595cb58dc5abddd17c975cc043e677250282d54071450034d75e77478361cbe43040b7d922222ee3677d679fceb2ed264598c5a01830022e4e0ea6a0
7
- data.tar.gz: be2ecf0661478e19f81b3e1904bc243e264e12b5842f54b583bca126a68011bb26620177eb7fa4d42a6384f6debdec55faa600f1d180ab782c795a62ccad8578
6
+ metadata.gz: 7254d3d366227ef2ad584512b7ebc3d518a3217038fcaef66265659ec6b6013796a69141343e4af6b39b1d8d8a755238a52116e0a567e782e735f972aa6656d7
7
+ data.tar.gz: 3a6e491075503f6cbf27234475be5b5334ef738be8fdd324e5d1d0a36f9968e2b4d25bcbfa8668a536c84e3f8881cebb34c0783c349fa0e2c5513f9d5d8ec19a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.1.0
2
+
3
+ * Fix optional argument handling and help text generation
4
+
5
+ * Update default help text
6
+
7
+ *Pavol Zbell*
8
+
9
+ ## 0.0.2
10
+
11
+ * Fix gem files
12
+
13
+ *Pavol Zbell*
14
+
1
15
  ## 0.0.1
2
16
 
3
17
  * Add initial extension to standard command line option parsing, setup Gem environment and RSpec tests
data/README.md CHANGED
@@ -16,10 +16,12 @@ partial argument analysis. Builds Git-like options and help by default.
16
16
 
17
17
  ## Usage
18
18
 
19
- Binds local variables to `ARGV` and parses command line arguments:
19
+ Bind local variables to `ARGV` and parse command line arguments:
20
20
 
21
21
  ```ruby
22
- ARGV #=> ['--no-verbose' '-o', 'file.out', 'file.in']
22
+ require 'optbind'
23
+
24
+ ARGV #=> ['--no-verbose', '-o', 'file.out', 'file.in']
23
25
 
24
26
  i, o, v = STDIN, STDOUT, true
25
27
 
@@ -1,3 +1,3 @@
1
1
  module OptBind
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/optbind.rb CHANGED
@@ -26,9 +26,9 @@ class OptionBinder
26
26
 
27
27
  def resolve_parser(parser = nil)
28
28
  parser || OptionParser.new do |p|
29
- p.define_singleton_method(:banner) { (b = super()) !~ /\AU/ ? b : "usage: #{program_name}\n\n" }
29
+ p.define_singleton_method(:banner) { (b = super()) !~ /\AU/ ? b : "usage: #{program_name} [<options>]\n\n" }
30
30
  p.define_singleton_method(:version) { super() || (defined?(::VERSION) && ::VERSION) }
31
- p.define_singleton_method(:help) { super() << " -h, --help\n --version\n\n" }
31
+ p.define_singleton_method(:help) { super().gsub(/(-\S+)=\[/, '\1[=') << " -h, --help\n --version\n\n" }
32
32
  end
33
33
  end
34
34
 
@@ -95,7 +95,7 @@ class OptionBinder
95
95
  opts, handler, bound, variable, default = *several_variants(*opts, &handler)
96
96
 
97
97
  @parser.on(*opts) do |r|
98
- unless opts.include? :OPTIONAL
98
+ if opts.include? :REQUIRED
99
99
  a = opts.select { |o| o =~ /\A-/ }.sort_by { |o| o.length }[-1]
100
100
  @parser.abort "missing argument: #{a}=" if !r || (r.respond_to?(:empty?) && r.empty?)
101
101
  end
@@ -147,7 +147,6 @@ class OptionBinder
147
147
 
148
148
  pattern = hash[:pattern] || hash[:type]
149
149
  values = hash[:values]
150
-
151
150
  names = [hash[:long], hash[:longs]].flatten.map { |n| n.to_s.sub(/\A-{,2}/, '--') if n }
152
151
  names += [hash[:short], hash[:shorts]].flatten.map { |n| n.to_s.sub(/\A-{,2}/, '-') if n }
153
152
  names += [hash[:name], hash[:names]].flatten.map do |n|
@@ -157,7 +156,7 @@ class OptionBinder
157
156
  n[2] ? "--#{n}" : "-#{n}"
158
157
  end
159
158
 
160
- argument = (hash[:argument].to_s if hash[:argument])
159
+ argument = (hash[:argument].to_s.sub(/\A\[=/, '=[') if hash[:argument])
161
160
  description = ([hash[:description]].flatten * ' ' if hash[:description])
162
161
  handler ||= hash[:handler]
163
162
  return ([style, pattern, values] + names + [argument, description]).compact, handler
@@ -173,18 +172,18 @@ class OptionBinder
173
172
  style, pattern, values, argument = nil
174
173
 
175
174
  while string.sub!(/\A(?:(?<long>--[\[\]\-\w]+[\]\w]+)?(?:(?<argument>\[?=[<(]\S+[)>]\.{,3}\]?)|\s+))/, '')
176
- longs << $~[:long]
175
+ longs << $~[:long] if $~[:long]
176
+ next unless $~[:argument]
177
177
  argument = $~[:argument]
178
-
179
- next unless argument
180
-
181
178
  style = argument[0] == '=' ? :REQUIRED : :OPTIONAL
182
179
  values = $~[:values].split('|') if argument =~ /\[?=\((?<values>\S*)\)\]?/
183
180
 
184
181
  if values.nil? && argument =~ /\[?=<(?<name>\S+):(?<pattern>\S+)>\]?/
185
182
  pattern = Module.const_get($~[:pattern]) rescue Regexp.new($~[:pattern])
186
183
  argument = "=<#{$~[:name]}>"
187
- argument = "[#{argument}]" if style == :OPTIONAL
184
+ argument = "=[#{argument[1..-1]}]" if style == :OPTIONAL
185
+ else
186
+ argument.sub!(/\A\[=/, '=[')
188
187
  end
189
188
  end
190
189
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavol Zbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-31 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler