lab42_options 0.1.0 → 0.2.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: 89f7aaf93a227feba15aea3a108e7d03dcde0042
4
- data.tar.gz: 6237261e7e8ffe64140ad442540eb98010bd070a
3
+ metadata.gz: fc16f86cc55f71e19a7c41cd024131a53e2968db
4
+ data.tar.gz: 47887a14848a7d6c666f48a1d908c93577e152f9
5
5
  SHA512:
6
- metadata.gz: 99e69a7290052a99a017596ef79681c7d3d02d63ddfb7b6a92503906238579338384e5f8a31c72c54727d016bb7a65361cea22acb60d085dedbd1e3bbcca7be2
7
- data.tar.gz: c45b3d89c9b9221d40251b2694c3799c7b38f6fb2d09ae239f3ae9f937d9a5ae989728bb6775a99baf7f84a271d10c35bcb157f07f78f083b934a88b2f9be333
6
+ metadata.gz: 777cf27a5727f4ce0484f72c3e2364a697b47732e748b2d6d1e6960305d4e237afeecdff4c500a4ee8ba420084a1842d6ef1d55d4868c4e4635f41212b556e25
7
+ data.tar.gz: e9f5f84c8b68bcc8cd44dbd9efd24517a198af1c6057f562df62ee34dff0571dc5f2bd3e2296cfadf9643d8637732612725924c091e54e972dc02eb1ca6ff257
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Lets us specify command line options with the same syntax as ruby parameters
6
6
 
7
7
  ```
8
- my_shiny_gem "hello", "world", :verbose, answer: 42
8
+ my_shiny_gem "hello" "world" :verbose answer: 42
9
9
  ```
10
10
 
11
11
  Will yield
@@ -21,3 +21,36 @@ Will yield
21
21
  options[:answer] # --> "42"
22
22
  options.answer # --> "42"
23
23
  ```
24
+
25
+ ## Multiple values
26
+
27
+ When providing the same key many times the options object will become an array
28
+
29
+ ```
30
+ my_even_shiner_gem 42 tag: cool :mixed tag: hot mixed: pickels
31
+ ```
32
+
33
+ Will yield
34
+
35
+ ```ruby
36
+
37
+ options.args # --> %W{42}
38
+ options[:tag] # --> %W{cool hot}
39
+ options.mixed # --> [true, "pickels"]
40
+ ```
41
+
42
+ ## Missing Features
43
+
44
+ * Help Message Generation
45
+
46
+ https://github.com/RobertDober/lab42_options/issues/3
47
+
48
+ * Required Arguments
49
+
50
+ https://github.com/RobertDober/lab42_options/issues/2
51
+
52
+ * Default Arguments
53
+
54
+ https://github.com/RobertDober/lab42_options/issues/2
55
+
56
+ * Typed Arguments
@@ -1,5 +1,7 @@
1
1
  require 'ostruct'
2
2
  class OpenStruct
3
+ # Given the value of `key` can be converted to a Hash
4
+ # Then will return a new `OpenStruct` _augmented_ by this hash
3
5
  def forwarding_to key
4
6
  h = to_h
5
7
  k = self[key].to_h
@@ -16,15 +16,20 @@ module Lab42
16
16
  loop do
17
17
  case current = e.next
18
18
  when /\A:(.*)/
19
- kwds.update $1.to_sym => true
19
+ update_value $1.to_sym, true
20
20
  when /\A(.*):\z/
21
- kwds.update $1.to_sym => e.next
21
+ update_value $1.to_sym, e.next
22
22
  else
23
23
  positionals << current
24
24
  end
25
25
  end
26
26
  end
27
-
27
+
28
+ def update_value key, val
29
+ kwds.merge! key => val do |k, oldv, newv|
30
+ Array( oldv ) << newv
31
+ end
32
+ end
28
33
  end
29
34
  end
30
35
  end
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  class Options
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_options
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry