optparse2 0.2.0 → 0.2.2
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 +4 -4
- data/lib/optparse2/pathname.rb +8 -0
- data/lib/optparse2/version.rb +1 -1
- data/lib/optparse2.rb +34 -6
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66bb4c0d5cb63aeb00892107109747ed067ce775735197988fc4ee4440838dc5
|
|
4
|
+
data.tar.gz: 7fb6c93ed46fbcd593efbc279cdf5cea118fb0b124da773d0bf1b769683e23e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94638934a52eacb19e61fad8226ba7f4e213e9d63b20cd95446c1afb257e5ef8f957d55f14975a6ed28a37807b8bd61b733b0a6d7eb94686c51ad412097ece29
|
|
7
|
+
data.tar.gz: 1b07050a1560dbeacc46ce0c1c73833966492b9770a92fca79a3c269b389c6ed1fa6e54a07f4aa60e8fcb9ee03ba4c4ae9111fecf951d8eaa156dfa01f73e64c
|
data/lib/optparse2/version.rb
CHANGED
data/lib/optparse2.rb
CHANGED
|
@@ -21,13 +21,17 @@ class OptParse2
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def switch_name=(val)
|
|
24
|
+
# binding.irb
|
|
25
|
+
@switch_name = val
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def set_block_name_because_of_switch_name
|
|
24
29
|
if @block.nil? && @arg.nil?
|
|
25
|
-
q = switch_name.to_sym
|
|
30
|
+
q = @switch_name.to_sym
|
|
26
31
|
@block = proc { q }
|
|
27
32
|
end
|
|
28
|
-
# binding.irb
|
|
29
|
-
@switch_name = val
|
|
30
33
|
end
|
|
34
|
+
|
|
31
35
|
# attr_writer :switch_name
|
|
32
36
|
def switch_name; defined?(@switch_name) ? @switch_name : super end
|
|
33
37
|
|
|
@@ -58,10 +62,18 @@ class OptParse2
|
|
|
58
62
|
sw, *rest = super(opts, block)
|
|
59
63
|
|
|
60
64
|
sw.extend Helpers
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
if key
|
|
66
|
+
sw.switch_name = key
|
|
67
|
+
sw.set_block_name_because_of_switch_name
|
|
68
|
+
end
|
|
63
69
|
sw.set_hidden if hidden
|
|
64
70
|
|
|
71
|
+
if (not_style = rest[2])
|
|
72
|
+
not_style.extend Helpers
|
|
73
|
+
not_style.switch_name = key if key
|
|
74
|
+
not_style.set_hidden if hidden
|
|
75
|
+
end
|
|
76
|
+
|
|
65
77
|
if nodefault && default_description != nil
|
|
66
78
|
raise ArgumentError, "default: not supplied, but default_description: given"
|
|
67
79
|
elsif not nodefault
|
|
@@ -91,7 +103,7 @@ class OptParse2
|
|
|
91
103
|
result = super(argv, into: already_done, **keywords, &nonopt)
|
|
92
104
|
|
|
93
105
|
@defaults.each do |sw|
|
|
94
|
-
key = sw.switch_name
|
|
106
|
+
key = sw.switch_name.to_sym
|
|
95
107
|
next if already_done.key? key
|
|
96
108
|
into[key] = sw.default()
|
|
97
109
|
end
|
|
@@ -99,3 +111,19 @@ class OptParse2
|
|
|
99
111
|
result
|
|
100
112
|
end
|
|
101
113
|
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
require_relative 'optparse2/pathname'
|
|
117
|
+
require_relative 'optparse2/globals'
|
|
118
|
+
$* << '-tFOO' << '--no-cache' << '-x'
|
|
119
|
+
OPTS={}
|
|
120
|
+
OptParse2.new do |op|
|
|
121
|
+
op.on '--[no-]cache-file=PATH', Pathname, default: :LOL
|
|
122
|
+
op.on '-x', '--lol', key: :a123
|
|
123
|
+
op.on '--period=PERIOD', Integer
|
|
124
|
+
op.on '-t', '--ticker=TICKER', &:upcase
|
|
125
|
+
|
|
126
|
+
op.parse! into: OPTS
|
|
127
|
+
p OPTS
|
|
128
|
+
# op.abort 'a ticker must be supplied' unless OPTS[:ticker]
|
|
129
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: optparse2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SamW
|
|
@@ -21,6 +21,7 @@ files:
|
|
|
21
21
|
- lib/optparse2.rb
|
|
22
22
|
- lib/optparse2/fixes.rb
|
|
23
23
|
- lib/optparse2/globals.rb
|
|
24
|
+
- lib/optparse2/pathname.rb
|
|
24
25
|
- lib/optparse2/version.rb
|
|
25
26
|
- sig/optparse2.rbs
|
|
26
27
|
licenses:
|