optparse-range 0.0.1 → 0.0.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.
- data/README.markdown +34 -13
- data/lib/optparse/range.rb +7 -7
- data/optparse-range.gemspec +4 -1
- data/test/test_range.rb +3 -3
- metadata +19 -6
data/README.markdown
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
OptionParser::Range
|
2
2
|
===================
|
3
3
|
|
4
|
-
|
4
|
+
[](http://travis-ci.org/KitaitiMakoto/optparse-range)
|
5
5
|
|
6
|
-
|
6
|
+
This RubyGem allows standard bundled [`OptionParser`][optparse] to accept option arguments as `Range` object.
|
7
|
+
|
8
|
+
Inspired by [Slop][slop] gem's [Range][sloprange] feature.
|
7
9
|
|
8
10
|
Note that `OptionParser::Range` module doesn't exist.
|
9
11
|
|
@@ -28,26 +30,26 @@ Usage
|
|
28
30
|
require 'optparse/range'
|
29
31
|
|
30
32
|
opts = OptionParser.new do |opti|
|
31
|
-
opti.on '--page=STARTPAGE-ENDPAGE', OptionParser::
|
33
|
+
opti.on '--page=STARTPAGE-ENDPAGE', OptionParser::DecimalIntegerRange
|
32
34
|
end.getopts
|
33
35
|
# for instance, when --page=024-160 passed
|
34
36
|
opts #=> {"page"=>24..160}
|
35
37
|
opts['page'].class #=> Range
|
36
38
|
|
37
|
-
When only one argument passed, it handled as both start and end:
|
39
|
+
When only one argument passed, it will be handled as both start and end:
|
38
40
|
|
39
41
|
opts = OptionParser.new do |opti|
|
40
|
-
opti.on '--port=STARTPORT-ENDPORT', OptionParser::
|
42
|
+
opti.on '--port=STARTPORT-ENDPORT', OptionParser::DecimalIntegerRange
|
41
43
|
end
|
42
44
|
# when --port=8080
|
43
45
|
opts #=> {"port"=>8080..8080}
|
44
46
|
|
45
|
-
You can replace `OptionParser::
|
47
|
+
You can replace `OptionParser::DecimalIntegerRange` in above example with other type of `Range`.
|
46
48
|
Currently provided:
|
47
49
|
|
48
|
-
### `OptionParser::
|
50
|
+
### `OptionParser::DecimalIntegerRange` ###
|
49
51
|
|
50
|
-
* `Integer` range
|
52
|
+
* decimal `Integer` range
|
51
53
|
* `--number=1-5` => `1..5`
|
52
54
|
* only zero or positive integers are supported currently
|
53
55
|
|
@@ -74,7 +76,7 @@ Currently provided:
|
|
74
76
|
### `OptionParser::StringRange` ###
|
75
77
|
|
76
78
|
* `String` range
|
77
|
-
* `--chars=A-Z` => `"A".."Z"`
|
79
|
+
* `--password-chars=A-Z` => `"A".."Z"`
|
78
80
|
|
79
81
|
Adding Type of Rnage
|
80
82
|
--------------------
|
@@ -122,6 +124,17 @@ Result:
|
|
122
124
|
$ ./mycommand --myoption=mystart-myend
|
123
125
|
{"myoption"=>#<MyClass:0x000000031824c0 @arg="mystart">..#<MyClass:0x00000003182420 @arg="myend">}
|
124
126
|
|
127
|
+
Todos
|
128
|
+
-----
|
129
|
+
|
130
|
+
* More comments for YARD
|
131
|
+
* Negative numbers
|
132
|
+
* More classes
|
133
|
+
* `OptioniParser#accept_range`
|
134
|
+
* List of range(--page=1-3,6-7)
|
135
|
+
* API for `Range` excluding the end point(`1...5` in result)
|
136
|
+
* Range with single point, such like --age=-18(under 18) or --page=192-(all after page 192)
|
137
|
+
|
125
138
|
Contributing
|
126
139
|
------------
|
127
140
|
|
@@ -131,12 +144,20 @@ Contributing
|
|
131
144
|
4. Push to the branch (`git push origin my-new-feature`)
|
132
145
|
5. Create new Pull Request
|
133
146
|
|
147
|
+
Links
|
148
|
+
-----
|
149
|
+
|
150
|
+
* [Homepage and source code][repo]
|
151
|
+
* [Referencees][rubydoc]
|
152
|
+
|
153
|
+
[optparse]: http://rubydoc.info/stdlib/optparse/frames
|
154
|
+
[slop]: https://github.com/injekt/slop
|
155
|
+
[sloprange]: https://github.com/injekt/slop/wiki/Ranges
|
156
|
+
[repo]: https://github.com/KitaitiMakoto/optparse-range
|
157
|
+
[rubydoc]: http://rubydoc.info/gems/optparse-range/frames
|
158
|
+
|
134
159
|
License
|
135
160
|
-------
|
136
161
|
|
137
162
|
OptionParser::Range is released under the Ruby's license.
|
138
163
|
See the file LICENSE.txt.
|
139
|
-
|
140
|
-
<!-- Links -->
|
141
|
-
[slop]: https://github.com/injekt/slop
|
142
|
-
[sloprange]: https://github.com/injekt/slop/wiki/Ranges
|
data/lib/optparse/range.rb
CHANGED
@@ -4,18 +4,18 @@ class OptionParser
|
|
4
4
|
class << self
|
5
5
|
def accept_range(accepter, converter)
|
6
6
|
accept accepter do |range,|
|
7
|
-
return unless range
|
8
|
-
|
9
|
-
raise AmbiguousArgument if
|
10
|
-
|
11
|
-
Range.new *
|
7
|
+
return range unless range
|
8
|
+
points = range.split('-')
|
9
|
+
raise AmbiguousArgument if points.length > 2
|
10
|
+
points << points.first if points.length == 1
|
11
|
+
Range.new *points.map(&converter)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
decimal = '\d+(?:_\d+)*'
|
17
|
-
|
18
|
-
accept_range
|
17
|
+
DecimalIntegerRange = /#{decimal}(?:\-#{decimal})/io
|
18
|
+
accept_range DecimalIntegerRange, :to_i
|
19
19
|
|
20
20
|
float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
|
21
21
|
FloatRange = /#{float}-#{float}/io
|
data/optparse-range.gemspec
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "optparse-range"
|
3
|
-
gem.version = '0.0.
|
3
|
+
gem.version = '0.0.2'
|
4
4
|
gem.authors = ["KITAITI Makoto"]
|
5
5
|
gem.email = ["KitaitiMakoto@gmail.com"]
|
6
6
|
gem.description = %q{This RubyGem allows standard bundled `OptionParser` to accept option arguments as `Range` object.}
|
7
7
|
gem.summary = %q{Range command line arguments handling}
|
8
8
|
gem.homepage = "https://github.com/KitaitiMakoto/optparse-range"
|
9
|
+
gem.licenses = ['Ruby', 'BSDL']
|
9
10
|
|
10
11
|
gem.files = `git ls-files`.split($/)
|
11
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
14
|
gem.require_paths = ["lib"]
|
15
|
+
|
16
|
+
gem.add_development_dependency 'rake'
|
14
17
|
end
|
data/test/test_range.rb
CHANGED
@@ -7,9 +7,9 @@ class TestOptionParserRange < Test::Unit::TestCase
|
|
7
7
|
@opt = OptionParser.new
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
assert_equal 81..123, parse_option(OptionParser::
|
12
|
-
assert_equal 1..1, parse_option(OptionParser::
|
10
|
+
def test_decimal_integer_range
|
11
|
+
assert_equal 81..123, parse_option(OptionParser::DecimalIntegerRange, '081-123')
|
12
|
+
assert_equal 1..1, parse_option(OptionParser::DecimalIntegerRange, '1')
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_float_range
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optparse-range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-07-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &9890840 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *9890840
|
14
25
|
description: This RubyGem allows standard bundled `OptionParser` to accept option
|
15
26
|
arguments as `Range` object.
|
16
27
|
email:
|
@@ -32,7 +43,9 @@ files:
|
|
32
43
|
- test/test_range.rb
|
33
44
|
- test/test_range.rb~
|
34
45
|
homepage: https://github.com/KitaitiMakoto/optparse-range
|
35
|
-
licenses:
|
46
|
+
licenses:
|
47
|
+
- Ruby
|
48
|
+
- BSDL
|
36
49
|
post_install_message:
|
37
50
|
rdoc_options: []
|
38
51
|
require_paths:
|
@@ -45,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
58
|
version: '0'
|
46
59
|
segments:
|
47
60
|
- 0
|
48
|
-
hash:
|
61
|
+
hash: -3406969379377498209
|
49
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
63
|
none: false
|
51
64
|
requirements:
|
@@ -54,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
67
|
version: '0'
|
55
68
|
segments:
|
56
69
|
- 0
|
57
|
-
hash:
|
70
|
+
hash: -3406969379377498209
|
58
71
|
requirements: []
|
59
72
|
rubyforge_project:
|
60
73
|
rubygems_version: 1.8.8
|