opt-simple 0.9.6 → 0.9.7
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.
- data/README +8 -29
- data/lib/opt_simple.rb +7 -3
- data/test/test_help.rb +1 -1
- data/test/test_usage.rb +10 -0
- metadata +2 -2
data/README
CHANGED
|
@@ -40,7 +40,7 @@ It is recommended to install OptSimple using RubyGems:
|
|
|
40
40
|
require 'opt_simple'
|
|
41
41
|
|
|
42
42
|
defaults = {
|
|
43
|
-
:
|
|
43
|
+
:num_results => 42,
|
|
44
44
|
:range => [5,10]
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -83,11 +83,13 @@ It is recommended to install OptSimple using RubyGems:
|
|
|
83
83
|
# will be integers if set on the CL
|
|
84
84
|
puts "Cowbell: #{opts['cowbell']}"
|
|
85
85
|
|
|
86
|
-
#
|
|
87
|
-
puts "N: #{opts
|
|
86
|
+
# Dashes will be replaced by underscores so that method syntax works nicely
|
|
87
|
+
puts "N: #{opts.num_values}"
|
|
88
|
+
puts "N: #{opts['num-values']}"
|
|
88
89
|
|
|
89
90
|
# You can check to see if Options were set
|
|
90
|
-
|
|
91
|
+
# and you can use hash syntax to access the options as strings or symbols
|
|
92
|
+
puts "Pattern: #{opts[:p]}" if opts.include?(:p)
|
|
91
93
|
|
|
92
94
|
# Here, range was set to an Array.
|
|
93
95
|
puts "Range: #{opts.range.first} #{opts.range.last}"
|
|
@@ -124,7 +126,7 @@ Which prints out an automatic usage statement:
|
|
|
124
126
|
puts "Options"
|
|
125
127
|
puts options
|
|
126
128
|
|
|
127
|
-
=== An example
|
|
129
|
+
=== An example using all default behavior
|
|
128
130
|
|
|
129
131
|
require 'opt_simple'
|
|
130
132
|
|
|
@@ -138,7 +140,7 @@ Which prints out an automatic usage statement:
|
|
|
138
140
|
puts "Options"
|
|
139
141
|
puts options
|
|
140
142
|
|
|
141
|
-
=== An example that shows how to
|
|
143
|
+
=== An example that shows how to set the banner string, and add a summary.
|
|
142
144
|
|
|
143
145
|
require 'opt_simple'
|
|
144
146
|
|
|
@@ -159,29 +161,6 @@ Which prints out an automatic usage statement:
|
|
|
159
161
|
puts "Options"
|
|
160
162
|
puts options
|
|
161
163
|
|
|
162
|
-
=== An example that shows how to use 'accumulate_opt' on an option to create a list, and on a flag to increment a counter
|
|
163
|
-
|
|
164
|
-
require 'opt_simple'
|
|
165
|
-
|
|
166
|
-
verbosity = 0
|
|
167
|
-
|
|
168
|
-
options = OptSimple.new.parse_opts! do
|
|
169
|
-
option %w[-i --infile], "Infile, multiple allowed", "FILE" do | arg |
|
|
170
|
-
accumulate_opt arg
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
flag %w[-v --verbose],"Verbosity. the more you set, the more we give" do
|
|
174
|
-
verbosity += 1
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
flag %w[-m --more-cow-bell], "I've got a fever" do
|
|
178
|
-
accumulate_opt
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
puts "Options"
|
|
183
|
-
puts options
|
|
184
|
-
|
|
185
164
|
=== An example that shows that you can easily set your defaults in normal Ruby variables and provide your own help.
|
|
186
165
|
|
|
187
166
|
require 'opt_simple'
|
data/lib/opt_simple.rb
CHANGED
|
@@ -19,7 +19,7 @@ The number of arguments are determined by the 'arity' of the block.
|
|
|
19
19
|
|
|
20
20
|
The order in which the parameters are defined dictate their order on the command line.
|
|
21
21
|
|
|
22
|
-
User defined help banners, summaries or the whole usage statement can be
|
|
22
|
+
User defined help banners, summaries or the whole usage statement can be set manually.
|
|
23
23
|
=end
|
|
24
24
|
class OptSimple
|
|
25
25
|
attr_accessor :args
|
|
@@ -290,7 +290,7 @@ class OptSimple
|
|
|
290
290
|
|
|
291
291
|
parm.names.each do | n |
|
|
292
292
|
if @param_names.has_key?(n)
|
|
293
|
-
raise OptSimple::Error.new "Command line switch already in use
|
|
293
|
+
raise OptSimple::Error.new "Command line switch already in use: #{n}"
|
|
294
294
|
else
|
|
295
295
|
@param_names[n] = true
|
|
296
296
|
end
|
|
@@ -328,7 +328,11 @@ class OptSimple
|
|
|
328
328
|
names = []
|
|
329
329
|
switches.each do |s|
|
|
330
330
|
st = s.sub(/^-+/,'')
|
|
331
|
-
names << st << st.to_sym
|
|
331
|
+
names << st << st.to_sym
|
|
332
|
+
if st.include?('-')
|
|
333
|
+
st2 = st.gsub('-','_')
|
|
334
|
+
names << st2 << st2.to_sym
|
|
335
|
+
end
|
|
332
336
|
end
|
|
333
337
|
names
|
|
334
338
|
end
|
data/test/test_help.rb
CHANGED
data/test/test_usage.rb
CHANGED
|
@@ -115,5 +115,15 @@ class TestHelpStatement < Test::Unit::TestCase
|
|
|
115
115
|
assert_equal o.v, false
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
+
must "add undersore versions to all switch names that have a dash" do
|
|
119
|
+
os = OptSimple.new({},%w[--some-stuff foo])
|
|
120
|
+
o = os.parse_opts! do
|
|
121
|
+
option %w[-s --some-stuff]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
assert o.include? 'some_stuff'
|
|
125
|
+
assert_equal o[:some_stuff],"foo"
|
|
126
|
+
end
|
|
127
|
+
|
|
118
128
|
end
|
|
119
129
|
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: opt-simple
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.9.
|
|
5
|
+
version: 0.9.7
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Ethan Stryker
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-03
|
|
13
|
+
date: 2011-04-03 00:00:00 +01:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies: []
|
|
16
16
|
|