opt-simple 0.9.3 → 0.9.4
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/lib/opt_simple.rb +10 -12
- data/test/test_arglist.rb +9 -4
- metadata +2 -2
data/lib/opt_simple.rb
CHANGED
@@ -74,18 +74,18 @@ class OptSimple
|
|
74
74
|
register_opts(&block)
|
75
75
|
end
|
76
76
|
|
77
|
-
# add the help option at the end, but only use -h if it hasn't been used
|
78
|
-
# already (cuz we're that nice).
|
79
|
-
help_strings = %w[-h --help]
|
80
|
-
if(@parameters.find {|p| p.switches.include?('-h')})
|
81
|
-
help_strings = %w[--help]
|
82
|
-
end
|
83
|
-
flag help_strings ,"(for this help message)"
|
84
|
-
|
85
77
|
if @parameters.empty?
|
86
78
|
#parse the @args array by looking for switches/args by regex
|
87
79
|
default_arg_parser
|
88
80
|
else
|
81
|
+
# add the help option at the end, but only use -h if it hasn't been used
|
82
|
+
# already (cuz we're that nice).
|
83
|
+
help_strings = %w[-h --help]
|
84
|
+
if(@parameters.find {|p| p.switches.include?('-h')})
|
85
|
+
help_strings = %w[--help]
|
86
|
+
end
|
87
|
+
flag help_strings ,"(for this help message)"
|
88
|
+
|
89
89
|
# go through the registered parameters, and pull out
|
90
90
|
# the specified parms from @arg
|
91
91
|
|
@@ -129,7 +129,6 @@ class OptSimple
|
|
129
129
|
unless intersection.empty?
|
130
130
|
mandatory_check.delete(parm.switches)
|
131
131
|
|
132
|
-
|
133
132
|
arg_locations = []
|
134
133
|
@args.each_with_index {|arg,i| arg_locations << i if intersection.include?(arg) }
|
135
134
|
|
@@ -166,9 +165,8 @@ class OptSimple
|
|
166
165
|
extra_switches = @args.find_all {|a| a.start_with?('-') }
|
167
166
|
raise OptSimple::InvalidOption.new "Unknown options: #{extra_switches.join(' ')}",self unless extra_switches.empty?
|
168
167
|
|
169
|
-
|
168
|
+
@results.positional_args = @args + positional_args
|
170
169
|
# put back the positional args that were taken off after the '--'
|
171
|
-
@results.positional_args.concat(@args.dup + positional_args)
|
172
170
|
@args.concat(positional_args)
|
173
171
|
end
|
174
172
|
|
@@ -191,7 +189,7 @@ class OptSimple
|
|
191
189
|
@args.each_with_index do |arg,loc|
|
192
190
|
if arg == '--'
|
193
191
|
# end of flag marker
|
194
|
-
@results.positional_args += @args[
|
192
|
+
@results.positional_args += @args[loc+1 .. -1]
|
195
193
|
break
|
196
194
|
elsif arg =~ /^-+(.*)/
|
197
195
|
# assume flags are boolean
|
data/test/test_arglist.rb
CHANGED
@@ -22,13 +22,18 @@ class ArglistTest < Test::Unit::TestCase
|
|
22
22
|
assert_equal options.positional_args.sort,%w[infile1 infile2 infile3 -infile4 infile5].sort
|
23
23
|
end
|
24
24
|
|
25
|
-
must "
|
25
|
+
must "keep positional args in ARGV when using parse_opts!" do
|
26
26
|
@os.parse_opts! &@block
|
27
27
|
assert_equal @args,%w[infile1 infile2 infile3 -infile4 infile5]
|
28
28
|
end
|
29
29
|
|
30
|
-
must "
|
31
|
-
|
30
|
+
must "keep positional args in ARGV when using parse_opts! and no block given" do
|
31
|
+
@os.parse_opts!
|
32
|
+
assert_equal @args,%w[infile1 infile3 -infile4 infile5]
|
33
|
+
end
|
34
|
+
|
35
|
+
must "have ARGV and opts.positional_args identical when calling parse_opts and no block given" do
|
36
|
+
opts = @os.parse_opts!
|
32
37
|
assert_equal @args,opts.positional_args
|
33
38
|
end
|
34
39
|
|
@@ -36,7 +41,7 @@ class ArglistTest < Test::Unit::TestCase
|
|
36
41
|
arg_copy = @args.dup
|
37
42
|
@os.parse_opts &@block
|
38
43
|
|
39
|
-
assert_equal @args
|
44
|
+
assert_equal @args,arg_copy
|
40
45
|
end
|
41
46
|
|
42
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opt-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Stryker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2011-03-
|
12
|
+
date: 2011-03-18 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|