optbind 0.5.0 → 0.5.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: 460ca3303bb62d3d9082fad5a691d3c96d0c68a7
4
- data.tar.gz: 279ef0028459cb0b10e90f4b25421d5894cb19eb
3
+ metadata.gz: e128bc6975c80a8f1261eca7bdf38743c2ad60ce
4
+ data.tar.gz: d4925a1d2d029ebbe05aba718f836b4b962b7494
5
5
  SHA512:
6
- metadata.gz: f0ea5b17c67992e22e74486b4260536d4e298e9fff683e3c367eb718a91ff78f01f3aa19c9c1f4f038d1af58cfa7d34dece47467d467a946a4e404cd603255fd
7
- data.tar.gz: d42a36c32091092fce179c4d480714e58f14ec45143a3ffd10dc86a4490b450ffdd0a5650ff01e07191dea701c6d13c11e95c8db82750ddb0b598d7db122c0c2
6
+ metadata.gz: 3ae1e8391bec9d3225eccf45093af663de0fce4a23f4ec0b994544128c68623a83f5d4d66b5b7135650aa3bb49980fbc56a77f5e592c43ebfa5bd6331076c1c0
7
+ data.tar.gz: b922fd19657c6be4def0a5f6357cf06df63a4b5985bdab264194c4dafb36dbaed35ee75ddf8a052c743ca3a4b8c2b1832aac220eb413b25918b0d3430724e19a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 0.5.0
2
+
3
+ * Support parsing of options with typed array value and multiple typed arguments
4
+
5
+ * Support underscore pattern syntax in string definitions
6
+
7
+ * Make parsing methods backwards compatible with `OptionParser` again
8
+
9
+ * Add extensions for parsing mode, known types, and custom handlers
10
+
11
+ * Add a lot of new test cases, minor bug fixes, and enhancements
12
+
13
+ *Pavol Zbell*
14
+
1
15
  ## 0.4.0
2
16
 
3
17
  * Support binding options to class variables
data/README.md CHANGED
@@ -265,7 +265,9 @@ Adds default values to option descriptions.
265
265
  ```ruby
266
266
  require 'optbind/default'
267
267
 
268
+ # ...
268
269
 
270
+ print binder.help
269
271
  ```
270
272
 
271
273
  #### Mode
@@ -275,7 +277,9 @@ Adds `order` and `permute` methods.
275
277
  ```ruby
276
278
  require 'optbind/mode'
277
279
 
278
- ARGV.order
280
+ # ...
281
+
282
+ binder.order ARGV
279
283
  ```
280
284
 
281
285
  Note that `order!` and `permute!` methods in `ARGV` from `OptionParser` are redefined to raise an unsupported error without this extension.
@@ -287,7 +291,7 @@ Adds various common types to accept in definitions.
287
291
  ```ruby
288
292
  require 'optbind/type'
289
293
 
290
- ...
294
+ # ...
291
295
 
292
296
  binder.option 'm --matcher=<pattern:Regexp>'
293
297
  binder.option 'r --repository=<uri:URI>'
@@ -300,7 +304,7 @@ Adds various common handlers to accept in definitions.
300
304
  ```ruby
301
305
  require 'optbind/handler'
302
306
 
303
- ...
307
+ # ...
304
308
 
305
309
  binder.option 's --storage=<name>', &included_in(%w(file memory))
306
310
  binder.option 'a --attachments=<ids>', &listed_as(Integer)
data/TODO.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # TODOS
2
2
 
3
+ - make a way to include all exts at once like require 'optbind/all'
3
4
  - test against special cases for multiple args like 'a <ids...>' with '--x 1'
4
5
  - add optbind/defaults from extise as separate package, required on demand
5
6
 
@@ -1,5 +1,19 @@
1
- module OptionBinder::Default
2
- # TODO
3
- end
1
+ require 'optbind'
2
+
3
+ class OptionBinder
4
+ alias_method :several_variants_without_default_description, :several_variants
5
+
6
+ def several_variants(*opts, &handler)
7
+ opts, handler, bound, variable, default = several_variants_without_default_description *opts, &handler
8
+ desc = opts.find { |o| o.is_a?(String) && o !~ /\A\s*[-=\[]/ }.tap { |d| opts.delete d if d }
4
9
 
5
- OptionBinder.prepend OptionBinder::Default
10
+ if !default.nil? && (!default.respond_to?(:empty?) || !default.empty?)
11
+ desc = "#{desc == nil || desc.empty? ? 'D' : "#{desc}, d"}efault #{[default] * ','}"
12
+ end
13
+
14
+ opts << desc if desc && !desc.empty?
15
+ return opts, handler, bound, variable, default
16
+ end
17
+
18
+ private :several_variants
19
+ end
@@ -1,3 +1,5 @@
1
+ require 'optbind'
2
+
1
3
  module OptionBinder::Handler
2
4
  def matched_by(p)
3
5
  -> (v) { p =~ v.to_s ? v : raise(OptionParser::InvalidArgument, v) if v }
data/lib/optbind/type.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'optbind'
2
3
 
3
4
  require 'optparse/date'
4
5
  require 'optparse/shellwords'
@@ -1,3 +1,3 @@
1
1
  class OptBind
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
data/lib/optbind.rb CHANGED
@@ -61,7 +61,7 @@ class OptionBinder
61
61
  def_delegator :@parser, :help
62
62
 
63
63
  def usage(*args)
64
- line = (args.flatten * ' ') << "\n"
64
+ line = (args * ' ') << "\n"
65
65
 
66
66
  if @parser.banner =~ /\Ausage:.+\n\n/i
67
67
  @parser.banner = "usage: #{program} #{line}"
@@ -152,7 +152,7 @@ class OptionBinder
152
152
  end
153
153
 
154
154
  argument = (hash[:argument].to_s.sub(/\A(\[)?=?/, '=\1') if hash[:argument])
155
- description = ([hash[:description]].flatten * ' ' if hash[:description])
155
+ description = ([hash[:description]] * ' ' if hash[:description])
156
156
  handler ||= hash[:handler]
157
157
  return (style + [pattern, values] + names + [argument, description]).compact, handler
158
158
  end
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavol Zbell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-07 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec