slop 3.0.0.rc1 → 3.0.0
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 +31 -0
- data/README.md +2 -5
- data/lib/slop.rb +8 -1
- data/lib/slop/commands.rb +3 -3
- data/lib/slop/option.rb +11 -7
- data/slop.gemspec +1 -1
- data/test/option_test.rb +4 -0
- data/test/slop_test.rb +8 -0
- metadata +5 -5
data/CHANGES.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
3.0.0 (2012-01-24)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* value_to_range returns an x..x range if the value looks like an integer.
|
5
|
+
* Lots of code refactoring
|
6
|
+
* Use TomDoc documentation
|
7
|
+
* Added `Slop::Commands` and removed existing command system
|
8
|
+
* Configuration options altered:
|
9
|
+
* `:optional` has been renamed to `:optional_argument`
|
10
|
+
* Added `:required` for mandatory options
|
11
|
+
* `:argument` now accepts an `:optional` symbol as well as boolean value
|
12
|
+
* Removed Slop instance methods:
|
13
|
+
* description=, description
|
14
|
+
* summary=, summary
|
15
|
+
* command
|
16
|
+
* on_empty
|
17
|
+
* on_noopts
|
18
|
+
* execute
|
19
|
+
* to_struct
|
20
|
+
* Added Slop instance methods:
|
21
|
+
* separator
|
22
|
+
* fetch_option
|
23
|
+
* add_callback
|
24
|
+
|
25
|
+
2.4.3 (2012-01-16)
|
26
|
+
------------------
|
27
|
+
|
28
|
+
* Allow the `:as` option to accept an object responding to :call for
|
29
|
+
custom type conversions (#45)
|
30
|
+
* Ensure negative integers are not parsed as possible options (#46)
|
31
|
+
|
1
32
|
2.4.2 (2011-12-18)
|
2
33
|
------------------
|
3
34
|
|
data/README.md
CHANGED
@@ -3,6 +3,8 @@ Slop
|
|
3
3
|
|
4
4
|
Slop is a simple option parser with an easy to remember syntax and friendly API.
|
5
5
|
|
6
|
+
This README is targeted at Slop v3.
|
7
|
+
|
6
8
|
Installation
|
7
9
|
------------
|
8
10
|
|
@@ -48,10 +50,6 @@ on :p, :password, 'Your password', :optional_argument => true
|
|
48
50
|
on '-p', 'password=?', 'Your password'
|
49
51
|
```
|
50
52
|
|
51
|
-
For more information about creating options, see the
|
52
|
-
[Creating Options](https://github.com/injekt/slop/wiki/Creating-Options)
|
53
|
-
wiki page.
|
54
|
-
|
55
53
|
You can also return your options as a Hash:
|
56
54
|
|
57
55
|
```ruby
|
@@ -91,7 +89,6 @@ Check out the following wiki pages for more features:
|
|
91
89
|
|
92
90
|
* [Ranges](https://github.com/injekt/slop/wiki/Ranges)
|
93
91
|
* [Auto Create](https://github.com/injekt/slop/wiki/Auto-Create)
|
94
|
-
* [Commands](https://github.com/injekt/slop/wiki/Commands)
|
95
92
|
|
96
93
|
Woah woah, why you hating on OptionParser?
|
97
94
|
------------------------------------------
|
data/lib/slop.rb
CHANGED
@@ -2,7 +2,9 @@ require 'slop/option'
|
|
2
2
|
require 'slop/commands'
|
3
3
|
|
4
4
|
class Slop
|
5
|
-
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
VERSION = '3.0.0'
|
6
8
|
|
7
9
|
# The main Error class, all Exception classes inherit from this class.
|
8
10
|
class Error < StandardError; end
|
@@ -228,6 +230,11 @@ class Slop
|
|
228
230
|
end
|
229
231
|
alias to_h to_hash
|
230
232
|
|
233
|
+
# Enumerable interface. Yields each Slop::Option.
|
234
|
+
def each(&block)
|
235
|
+
options.each(&block)
|
236
|
+
end
|
237
|
+
|
231
238
|
# Check for an options presence.
|
232
239
|
#
|
233
240
|
# Examples:
|
data/lib/slop/commands.rb
CHANGED
@@ -40,7 +40,7 @@ class Slop
|
|
40
40
|
#
|
41
41
|
# Returns the newly created Slop instance mapped to command.
|
42
42
|
def on(command, config = {}, &block)
|
43
|
-
commands[command] = Slop.new(@config.merge(config), &block)
|
43
|
+
commands[command.to_s] = Slop.new(@config.merge(config), &block)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Add a Slop instance used when no other commands exist.
|
@@ -50,7 +50,7 @@ class Slop
|
|
50
50
|
#
|
51
51
|
# Returns the newly created Slop instance mapped to default.
|
52
52
|
def default(config = {}, &block)
|
53
|
-
|
53
|
+
on('default', config, &block)
|
54
54
|
end
|
55
55
|
|
56
56
|
# Add a global Slop instance.
|
@@ -60,7 +60,7 @@ class Slop
|
|
60
60
|
#
|
61
61
|
# Returns the newly created Slop instance mapped to global.
|
62
62
|
def global(config = {}, &block)
|
63
|
-
|
63
|
+
on('global', config, &block)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Fetch the instance of Slop tied to a command.
|
data/lib/slop/option.rb
CHANGED
@@ -129,19 +129,23 @@ class Slop
|
|
129
129
|
|
130
130
|
private
|
131
131
|
|
132
|
-
# Convert an object to a Range if possible.
|
133
|
-
# what does *not* look like a Range, but looks like an Integer of some
|
134
|
-
# sort, it will call #to_i on the Object and return the Integer
|
135
|
-
# representation.
|
132
|
+
# Convert an object to a Range if possible.
|
136
133
|
#
|
137
134
|
# value - The Object we want to convert to a range.
|
138
135
|
#
|
139
136
|
# Returns the Range value if one could be found, else the original object.
|
140
137
|
def value_to_range(value)
|
141
|
-
|
142
|
-
|
138
|
+
case value.to_s
|
139
|
+
when /\A(\-?\d+)\z/
|
140
|
+
Range.new($1.to_i, $1.to_i)
|
141
|
+
when /\A(-?\d+?)(\.\.\.?|-|,)(-?\d+)\z/
|
142
|
+
Range.new($1.to_i, $3.to_i, $2 == '...')
|
143
143
|
else
|
144
|
-
|
144
|
+
if @slop.config[:strict]
|
145
|
+
raise InvalidArgumentError, "#{value} could not be coerced into Range"
|
146
|
+
else
|
147
|
+
value
|
148
|
+
end
|
145
149
|
end
|
146
150
|
end
|
147
151
|
|
data/slop.gemspec
CHANGED
data/test/option_test.rb
CHANGED
@@ -66,6 +66,10 @@ class OptionTest < TestCase
|
|
66
66
|
assert_equal (1...10), option_value(%w/-r 1...10/, :r=, :as => Range)
|
67
67
|
assert_equal (-1..10), option_value(%w/-r -1..10/, :r=, :as => Range)
|
68
68
|
assert_equal (1..-10), option_value(%w/-r 1..-10/, :r=, :as => Range)
|
69
|
+
assert_equal (1..1), option_value(%w/-r 1/, :r=, :as => Range)
|
70
|
+
|
71
|
+
opts = Slop.new(:strict => true) { on :r=, :as => Range }
|
72
|
+
assert_raises(Slop::InvalidArgumentError) { opts.parse %w/-r abc/ }
|
69
73
|
end
|
70
74
|
|
71
75
|
test "array type cast" do
|
data/test/slop_test.rb
CHANGED
@@ -23,6 +23,14 @@ class SlopTest < TestCase
|
|
23
23
|
$stderr = STDERR
|
24
24
|
end
|
25
25
|
|
26
|
+
test "includes Enumerable" do
|
27
|
+
assert_includes Slop.included_modules, Enumerable
|
28
|
+
end
|
29
|
+
|
30
|
+
test "enumerates Slop::Option objects in #each" do
|
31
|
+
Slop.new { on :f; on :b; }.each { |o| assert_kind_of Slop::Option, o }
|
32
|
+
end
|
33
|
+
|
26
34
|
test "build_option" do
|
27
35
|
assert_equal ['f', nil, nil, {}], build_option(:f)
|
28
36
|
assert_equal [nil, 'foo', nil, {}], build_option(:foo)
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Lee Jarvis
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-24 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
|
@@ -45,9 +45,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
46
|
none: false
|
47
47
|
requirements:
|
48
|
-
- - ! '
|
48
|
+
- - ! '>='
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: '0'
|
51
51
|
requirements: []
|
52
52
|
rubyforge_project:
|
53
53
|
rubygems_version: 1.8.11
|