slop 4.4.1 → 4.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de2091f9afde594e40aac061706815b7136bbf2c
4
- data.tar.gz: 9ba238ffb27744cbf3293cb532824f18a10f5e7e
3
+ metadata.gz: 4d27e2c3615ec37ec13f7a425eca0bd2095019f4
4
+ data.tar.gz: e9bd705f261dd6c8f91e53e48c4eb0afaa47b809
5
5
  SHA512:
6
- metadata.gz: a9701396bf3f9e1def3dbf17d38446f96ea560b7a046a3cab55783d053212a019a8f75102550dc67baf0df8b793dae0466ff1332fb0e42d0387cda143bdf20c2
7
- data.tar.gz: dbb443da3652723951432d1603bbf2fe614335ea0c7605d5e9bdffb04f06c5f4042bed5fe2880f64d3fec978bd14aef006fdb2946359e6db0368557bae12dda5
6
+ metadata.gz: fab6f8d628b08341f2d51f980a75654cb229e1a7a3412e0bc3fc3b19d39a0064adb7461a77a70fd491495e22ae766d464ea7850213320f64b41d72674e68080b
7
+ data.tar.gz: cca338b3042a5614a673f14a88b50fa990143a31c4c57faeaee3427476468074249ccc803ab7e2a67ad8f9cf31fc6877c87c09c14898ee2725393691edb7bd91
@@ -1,18 +1,15 @@
1
1
  cache: bundler
2
2
  before_install:
3
- - gem update bundler
3
+ - gem install bundler
4
4
  rvm:
5
5
  - 2.0.0
6
6
  - 2.1
7
7
  - 2.2
8
- - 2.3.0
9
- - rbx-2
8
+ - 2.3.4
9
+ - 2.4.1
10
+ - jruby-9.1.8.0
10
11
  - jruby-head
11
12
  - ruby-head
12
- matrix:
13
- allow_failures:
14
- - rvm: ruby-head
15
- - rvm: jruby-head
16
13
  notifications:
17
14
  email:
18
15
  on_success: change
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v4.4.2 (2017-06-29)
5
+ -------------------
6
+
7
+ Bug fixes:
8
+ * Fix support for parsing -x5 or -nfoo. #199
9
+ * Fix removing arguments after `--`. #194
10
+
4
11
  v4.4.1 (2016-08-21)
5
12
  -------------------
6
13
 
@@ -6,7 +6,7 @@ require 'slop/types'
6
6
  require 'slop/error'
7
7
 
8
8
  module Slop
9
- VERSION = '4.4.1'
9
+ VERSION = '4.4.2'
10
10
 
11
11
  # Parse an array of options (defaults to ARGV). Accepts an
12
12
  # optional hash of configuration options and block.
@@ -36,6 +36,9 @@ module Slop
36
36
  def parse(strings)
37
37
  reset # reset before every parse
38
38
 
39
+ # ignore everything after "--"
40
+ strings, ignored_args = partition(strings)
41
+
39
42
  pairs = strings.each_cons(2).to_a
40
43
  # this ensures we still support the last string being a flag,
41
44
  # otherwise it'll only be used as an argument.
@@ -47,12 +50,6 @@ module Slop
47
50
  flag, arg = pair
48
51
  break if !flag
49
52
 
50
- # ignore everything after '--', flag or not
51
- if flag == '--'
52
- arguments.delete(flag)
53
- break
54
- end
55
-
56
53
  # support `foo=bar`
57
54
  orig_flag = flag.dup
58
55
  orig_arg = arg
@@ -81,6 +78,8 @@ module Slop
81
78
  end
82
79
  end
83
80
 
81
+ @arguments += ignored_args
82
+
84
83
  Result.new(self).tap do |result|
85
84
  used_options.each { |o| o.finish(result) }
86
85
  end
@@ -111,13 +110,7 @@ module Slop
111
110
  elsif flag.start_with?("--no-") && option = matching_option(flag.sub("no-", ""))
112
111
  process(option, false)
113
112
  elsif flag =~ /\A-[^-]{2,}/
114
- # try and process as a set of grouped short flags. drop(1) removes
115
- # the prefixed -, then we add them back to each flag separately.
116
- flags = flag.split("").drop(1).map { |f| "-#{f}" }
117
- last = flags.pop
118
-
119
- flags.each { |f| try_process(f, nil) }
120
- try_process(last, arg) # send the argument to the last flag
113
+ try_process_smashed_arg(flag) || try_process_grouped_flags(flag, arg)
121
114
  else
122
115
  if flag.start_with?("-") && !suppress_errors?
123
116
  raise UnknownOption.new("unknown option `#{flag}'", "#{flag}")
@@ -125,6 +118,25 @@ module Slop
125
118
  end
126
119
  end
127
120
 
121
+ # try and process a flag with a "smashed" argument, e.g.
122
+ # -nFoo or -i5
123
+ def try_process_smashed_arg(flag)
124
+ option = matching_option(flag[0, 2])
125
+ if option && option.expects_argument?
126
+ process(option, flag[2..-1])
127
+ end
128
+ end
129
+
130
+ # try and process as a set of grouped short flags. drop(1) removes
131
+ # the prefixed -, then we add them back to each flag separately.
132
+ def try_process_grouped_flags(flag, arg)
133
+ flags = flag.split("").drop(1).map { |f| "-#{f}" }
134
+ last = flags.pop
135
+
136
+ flags.each { |f| try_process(f, nil) }
137
+ try_process(last, arg) # send the argument to the last flag
138
+ end
139
+
128
140
  def suppress_errors?
129
141
  config[:suppress_errors]
130
142
  end
@@ -132,5 +144,14 @@ module Slop
132
144
  def matching_option(flag)
133
145
  options.find { |o| o.flags.include?(flag) }
134
146
  end
147
+
148
+ private def partition(strings)
149
+ if strings.include?("--")
150
+ partition_idx = strings.index("--")
151
+ [strings[0..partition_idx-1], strings[partition_idx+1..-1]]
152
+ else
153
+ [strings, []]
154
+ end
155
+ end
135
156
  end
136
157
  end
@@ -11,8 +11,9 @@ describe Slop::Parser do
11
11
  end
12
12
 
13
13
  it "ignores everything after --" do
14
- @parser.parse %w(-v -- --name lee)
14
+ @parser.parse %w(-v -- -v --name lee)
15
15
  assert_equal [@verbose], @parser.used_options
16
+ assert_equal ["-v", "--name", "lee"], @parser.arguments
16
17
  end
17
18
 
18
19
  it "parses flag=argument" do
@@ -66,6 +67,19 @@ describe Slop::Parser do
66
67
  end
67
68
  end
68
69
 
70
+ describe "short flags with arguments" do
71
+ before do
72
+ @options.integer "-i"
73
+ @options.string "-s"
74
+ end
75
+
76
+ it "parses the argument" do
77
+ @result.parser.parse %w(-i5 -sfoo)
78
+ assert_equal 5, @result[:i]
79
+ assert_equal "foo", @result[:s]
80
+ end
81
+ end
82
+
69
83
  describe "#used_options" do
70
84
  it "returns all options that were parsed" do
71
85
  assert_equal [@verbose, @name], @parser.used_options
@@ -97,7 +97,7 @@ describe Slop::Result do
97
97
  end
98
98
 
99
99
  it "returns nil if nothing is found" do
100
- assert_equal nil, @result.option("foo")
100
+ assert_nil @result.option("foo")
101
101
  end
102
102
  end
103
103
 
@@ -41,7 +41,7 @@ describe Slop::IntegerOption do
41
41
 
42
42
  it "returns nil for non-numbers by default" do
43
43
  @result.parser.parse %w(--age hello)
44
- assert_equal nil, @result[:age]
44
+ assert_nil @result[:age]
45
45
  end
46
46
  end
47
47
 
@@ -59,7 +59,7 @@ describe Slop::FloatOption do
59
59
 
60
60
  it "returns nil for non-numbers by default" do
61
61
  @result.parser.parse %w(--apr hello)
62
- assert_equal nil, @result[:apr]
62
+ assert_nil @result[:apr]
63
63
  end
64
64
  end
65
65
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slop
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-21 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -100,4 +100,3 @@ test_files:
100
100
  - test/slop_test.rb
101
101
  - test/test_helper.rb
102
102
  - test/types_test.rb
103
- has_rdoc: