slop 4.2.0 → 4.2.1

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: 73d86e1d2fe70c0ce378fdf9e6c1ca771970b11b
4
- data.tar.gz: 1da89cf463e52371680e66a913b09c215b1ac730
3
+ metadata.gz: 46b97913fc755da80d6ce7680b9c62edaa097f18
4
+ data.tar.gz: e5717f5a2ae612a433f9b602a1fbb0692a75cb77
5
5
  SHA512:
6
- metadata.gz: 3b4448b3fad94248ecdb67c8cf6af710c588a3da82a20e3d9286c0be123bdd97373cb187b7b0ed4da0ee5a1e6c9a80b1de7e52ec055e268482b56eacdcf4c0ef
7
- data.tar.gz: b6ea3a312f1f8f5f7570b634d8f1ff42cee7e345067c3dbdaf037477c9b62e3e5c40d28a4515bf42a52bf3e506720b7b599dea25351d468001e4c0d17205ce87
6
+ metadata.gz: 80d06a261ab8201470395cc679f0b833ca16f1c340ba6fe4f0a819cbb6fec16b9b41bd86b46d745f27bdbc047a0fbd3b2a5038aaa897f561e657780858437da9
7
+ data.tar.gz: 102f8d9c8d39db648ef5bb2f9aeae9366ee5b98d83748e8aab076a948ff63699f3fc6ea4eb7371df28958afb9d9e8f97d70a8d7f6fb9ebe477894b07c6fc6ad5
@@ -1,8 +1,15 @@
1
+ cache: bundler
1
2
  rvm:
2
3
  - 2.0.0
3
4
  - 2.1
4
5
  - 2.2
5
6
  - rbx-2
7
+ - jruby-head
8
+ - ruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ - rvm: jruby-head
6
13
  notifications:
7
14
  email:
8
15
  on_success: change
@@ -1,6 +1,21 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ v4.2.1 (2015-11-25)
5
+ -------------------
6
+
7
+ Features:
8
+ * Better handling of option names with multiple words. #169 (Tim Rogers)
9
+
10
+ Minor enhancements:
11
+ * add ARGF notes to Arguments (README). #173 (Rick Hull)
12
+
13
+ Bug fixes:
14
+ * Fix arguments removed with option arguments. #182 (Naoki Mizuno)
15
+ * Fix bug where true is passed to BoolOption block regardless
16
+ of --no- prefix. #184 (Ben Brady)
17
+ * only raise MissingArgument if not `default_value`. #163 (Ben Brady)
18
+
4
19
  v4.2.0 (2015-04-18)
5
20
  -------------------
6
21
 
data/README.md CHANGED
@@ -101,6 +101,21 @@ end
101
101
  p opts.arguments #=> ["connect", "GET"] # also aliased to `args`
102
102
  ```
103
103
 
104
+ This is particularly useful when writing scripts with `ARGF`:
105
+
106
+ ```ruby
107
+ opts = Slop.parse do |blah|
108
+ # ...
109
+ end
110
+
111
+ # make sure sloptions aren't consumed by ARGF
112
+ ARGV.replace opts.arguments
113
+
114
+ ARGF.each { |line|
115
+ # ...
116
+ }
117
+ ```
118
+
104
119
  Arrays
105
120
  ------
106
121
 
@@ -6,7 +6,7 @@ require 'slop/types'
6
6
  require 'slop/error'
7
7
 
8
8
  module Slop
9
- VERSION = '4.2.0'
9
+ VERSION = '4.2.1'
10
10
 
11
11
  # Parse an array of options (defaults to ARGV). Accepts an
12
12
  # optional hash of configuration options and block.
@@ -47,11 +47,16 @@ module Slop
47
47
  def ensure_call(value)
48
48
  @count += 1
49
49
 
50
- if value.nil? && expects_argument? && !suppress_errors?
51
- raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
50
+ if value.nil? && expects_argument?
51
+ if default_value
52
+ @value = default_value
53
+ elsif !suppress_errors?
54
+ raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
55
+ end
56
+ else
57
+ @value = call(value)
52
58
  end
53
59
 
54
- @value = call(value)
55
60
  block.call(@value) if block.respond_to?(:call)
56
61
  end
57
62
 
@@ -53,6 +53,7 @@ module Slop
53
53
  end
54
54
 
55
55
  # support `foo=bar`
56
+ orig_flag = flag.dup
56
57
  if flag.include?("=")
57
58
  flag, arg = flag.split("=")
58
59
  end
@@ -60,8 +61,15 @@ module Slop
60
61
  if opt = try_process(flag, arg)
61
62
  # since the option was parsed, we remove it from our
62
63
  # arguments (plus the arg if necessary)
63
- arguments.delete(flag)
64
- arguments.delete(arg) if opt.expects_argument?
64
+ # delete argument first while we can find its index.
65
+ if opt.expects_argument?
66
+ arguments.each_with_index do |argument, i|
67
+ if argument == orig_flag && !orig_flag.include?("=")
68
+ arguments.delete_at(i + 1)
69
+ end
70
+ end
71
+ end
72
+ arguments.delete(orig_flag)
65
73
  end
66
74
  end
67
75
 
@@ -94,7 +102,7 @@ module Slop
94
102
  process(option, arg)
95
103
  elsif flag.start_with?("--no-") && option = matching_option(flag.sub("no-", ""))
96
104
  process(option, false)
97
- elsif flag =~ /\A-[^-]/ && flag.size > 2
105
+ elsif flag =~ /\A-[^-]{2,}/
98
106
  # try and process as a set of grouped short flags. drop(1) removes
99
107
  # the prefixed -, then we add them back to each flag separately.
100
108
  flags = flag.split("").drop(1).map { |f| "-#{f}" }
@@ -16,7 +16,7 @@ module Slop
16
16
 
17
17
  def call(value)
18
18
  self.explicit_value = value
19
- true
19
+ !force_false?
20
20
  end
21
21
 
22
22
  def value
@@ -92,5 +92,4 @@ module Slop
92
92
  true
93
93
  end
94
94
  end
95
-
96
95
  end
@@ -66,5 +66,15 @@ describe Slop::Parser do
66
66
  @parser.parse %w(-v -- --name lee)
67
67
  assert_equal %w(--name lee), @parser.arguments
68
68
  end
69
+
70
+ it "correctly removes the option argument" do
71
+ @parser.parse %w(lee --name lee lee)
72
+ assert_equal %w(lee lee), @parser.arguments
73
+ end
74
+
75
+ it "correctly removes options that use =" do
76
+ @parser.parse %w(lee --name=lee lee)
77
+ assert_equal %w(lee lee), @parser.arguments
78
+ end
69
79
  end
70
80
  end
@@ -32,6 +32,9 @@ describe Slop::Result do
32
32
  @options.string("--foo", default: "bar")
33
33
  @result.parser.parse %w()
34
34
  assert_equal "bar", @result[:foo]
35
+
36
+ @result.parser.parse %w(--foo)
37
+ assert_equal "bar", @result[:foo]
35
38
  end
36
39
 
37
40
  it "handles custom finishing" do
@@ -6,7 +6,9 @@ describe Slop::BoolOption do
6
6
  @verbose = @options.bool "--verbose"
7
7
  @quiet = @options.bool "--quiet"
8
8
  @inversed = @options.bool "--inversed", default: true
9
- @result = @options.parse %w(--verbose --no-inversed)
9
+ @bloc = @options.bool("--bloc"){|val| (@bloc_val ||= []) << val}
10
+ @result = @options.parse %w(--verbose --no-inversed
11
+ --bloc --no-bloc)
10
12
  end
11
13
 
12
14
  it "returns true if used" do
@@ -20,6 +22,10 @@ describe Slop::BoolOption do
20
22
  it "can be inversed via --no- prefix" do
21
23
  assert_equal false, @result[:inversed]
22
24
  end
25
+
26
+ it "will invert the value passed to &block via --no- prefix" do
27
+ assert_equal [true, false], @bloc_val
28
+ end
23
29
  end
24
30
 
25
31
  describe Slop::IntegerOption do
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.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Jarvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-18 00:00:00.000000000 Z
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake