slop 3.0.0 → 3.0.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.
- data/CHANGES.md +7 -0
- data/lib/slop.rb +11 -8
- data/slop.gemspec +1 -1
- data/test/option_test.rb +4 -1
- metadata +2 -2
data/CHANGES.md
CHANGED
data/lib/slop.rb
CHANGED
@@ -4,7 +4,7 @@ require 'slop/commands'
|
|
4
4
|
class Slop
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
VERSION = '3.0.
|
7
|
+
VERSION = '3.0.1'
|
8
8
|
|
9
9
|
# The main Error class, all Exception classes inherit from this class.
|
10
10
|
class Error < StandardError; end
|
@@ -335,7 +335,7 @@ class Slop
|
|
335
335
|
heads = options.reject(&:tail?)
|
336
336
|
tails = (options - heads)
|
337
337
|
opts = (heads + tails).select(&:help).map(&:to_s)
|
338
|
-
optstr = opts.map
|
338
|
+
optstr = opts.each_with_index.map { |o, i|
|
339
339
|
(str = @separators[i + 1]) ? [o, str].join("\n") : o
|
340
340
|
}.join("\n")
|
341
341
|
config[:banner] ? config[:banner] + "\n" + optstr : optstr
|
@@ -519,10 +519,13 @@ class Slop
|
|
519
519
|
config[:argument] = true if @config[:arguments]
|
520
520
|
config[:optional_argument] = true if @config[:optional_arguments]
|
521
521
|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
522
|
+
if objects.last.is_a?(Hash)
|
523
|
+
config = config.merge!(objects.last)
|
524
|
+
objects.pop
|
525
|
+
end
|
526
|
+
short = extract_short_flag(objects, config)
|
527
|
+
long = extract_long_flag(objects, config)
|
528
|
+
desc = objects[0].respond_to?(:to_str) ? objects.shift : nil
|
526
529
|
|
527
530
|
Option.new(self, short, long, desc, config, &block)
|
528
531
|
end
|
@@ -535,7 +538,7 @@ class Slop
|
|
535
538
|
flag = clean(objects.first)
|
536
539
|
|
537
540
|
if flag.size == 2 && flag[-1, 1] == '='
|
538
|
-
config[:argument]
|
541
|
+
config[:argument] ||= true
|
539
542
|
flag.chop!
|
540
543
|
end
|
541
544
|
|
@@ -552,7 +555,7 @@ class Slop
|
|
552
555
|
def extract_long_flag(objects, config)
|
553
556
|
flag = objects.first.to_s
|
554
557
|
if flag =~ /\A(?:--?)?[a-zA-Z][a-zA-Z0-9_-]+\=?\??\z/
|
555
|
-
config[:argument]
|
558
|
+
config[:argument] ||= true if flag[-1, 1] == '='
|
556
559
|
config[:optional_argument] = true if flag[-2, 2] == '=?'
|
557
560
|
objects.shift
|
558
561
|
clean(flag).sub(/\=\??\z/, '')
|
data/slop.gemspec
CHANGED
data/test/option_test.rb
CHANGED
@@ -52,7 +52,10 @@ class OptionTest < TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
test "integer type cast" do
|
55
|
-
|
55
|
+
opts = Slop.new
|
56
|
+
opts.on :f=, :as => Integer
|
57
|
+
opts.parse %w'-f 1'
|
58
|
+
assert_equal 1, opts[:f]
|
56
59
|
end
|
57
60
|
|
58
61
|
test "symbol type cast" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A simple DSL for gathering options and parsing the command line
|
15
15
|
email: lee@jarvis.co
|