opt-simple 0.9.2 → 0.9.3

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.
Files changed (3) hide show
  1. data/lib/opt_simple.rb +14 -7
  2. data/test/test_arglist.rb +7 -3
  3. metadata +2 -2
data/lib/opt_simple.rb CHANGED
@@ -36,8 +36,7 @@ class OptSimple
36
36
  @results = OptSimple::Result.new
37
37
  @longest_switch_len = 0
38
38
  @defaults = defaults
39
- @positional_args = []
40
- @args = args
39
+ @args = args.to_a # especially for jruby
41
40
  @banner = "Usage: #{File.basename($0)} [options]"
42
41
  @summary = ""
43
42
  @help = ""
@@ -98,9 +97,10 @@ class OptSimple
98
97
 
99
98
  mandatory_check = mandatory_opts.map {|m| m.switches}
100
99
 
100
+ positional_args = []
101
101
  if(loc = @args.index('--'))
102
102
  #remove the '--', but don't include it w/ positional arguments
103
- @positional_args += @args.slice!(loc..-1)[1..-1]
103
+ positional_args = @args.slice!(loc..-1)[1..-1]
104
104
  end
105
105
 
106
106
  # Handle the case where a user specifies --foo=bar, or --foo=bar,baz
@@ -165,11 +165,13 @@ class OptSimple
165
165
 
166
166
  extra_switches = @args.find_all {|a| a.start_with?('-') }
167
167
  raise OptSimple::InvalidOption.new "Unknown options: #{extra_switches.join(' ')}",self unless extra_switches.empty?
168
-
169
- @positional_args += @args.slice!(0..-1)
168
+
169
+
170
+ # put back the positional args that were taken off after the '--'
171
+ @results.positional_args.concat(@args.dup + positional_args)
172
+ @args.concat(positional_args)
170
173
  end
171
174
 
172
- @results.positional_args = @positional_args
173
175
  return @results
174
176
  end
175
177
 
@@ -203,7 +205,7 @@ class OptSimple
203
205
  @results.positional_args << arg
204
206
  end
205
207
  end
206
- @args.slice!(0..-1)
208
+ @args.delete_if {|a| not @results.positional_args.include?(a)}
207
209
  end
208
210
 
209
211
  # Registers an optional parameter, usually with nothing following it.
@@ -513,6 +515,11 @@ class OptSimple
513
515
  end
514
516
  end
515
517
 
518
+ # check to see if the 'key' option was set
519
+ def include?(key)
520
+ @inside_hash.include?(@name_to_aliases[key])
521
+ end
522
+
516
523
  # a list of all the aliases
517
524
  def aliases
518
525
  @name_to_aliases.values.uniq
data/test/test_arglist.rb CHANGED
@@ -22,10 +22,14 @@ 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 "empty out ARGV when using parse_opts!" do
26
- arg_copy = @args.dup
25
+ must "only keep positional args in ARGV when using parse_opts!" do
27
26
  @os.parse_opts! &@block
28
- assert @args.empty?
27
+ assert_equal @args,%w[infile1 infile2 infile3 -infile4 infile5]
28
+ end
29
+
30
+ must "have ARGV and opts.positional_args identical when calling parse_opts!" do
31
+ opts = @os.parse_opts! &@block
32
+ assert_equal @args,opts.positional_args
29
33
  end
30
34
 
31
35
  must "preserve ARGV when using parse_opts" do
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.2
4
+ version: 0.9.3
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-16 00:00:00 +00:00
12
+ date: 2011-03-17 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15