optparse-off 0.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/LICENSE.txt +22 -0
- data/README.markdown +85 -0
- data/Rakefile +16 -0
- data/lib/optparse/off.rb +18 -0
- data/optparse-off.gemspec +14 -0
- data/test/test_off.rb +58 -0
- metadata +53 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 KITAITI Makoto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
OptionParser#off
|
2
|
+
================
|
3
|
+
|
4
|
+
Add a functionality which remove options already added to OptionParser.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'optparse-off'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install optparse-off
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
require 'optparse/off'
|
25
|
+
|
26
|
+
opts = OptionParser.new
|
27
|
+
opts.on '-n'
|
28
|
+
opts.off '-n'
|
29
|
+
opts.parse '-n' #=> invalid option: -n (OptionParser::InvalidOption)
|
30
|
+
|
31
|
+
Use case
|
32
|
+
--------
|
33
|
+
|
34
|
+
Let you use a simple framework for command-line applications.
|
35
|
+
|
36
|
+
# command.rb
|
37
|
+
require 'optparse'
|
38
|
+
|
39
|
+
class Command
|
40
|
+
def initialize
|
41
|
+
@opts = OptionParser.new
|
42
|
+
@opts.on '--dry-run' do |switch|
|
43
|
+
@dry_run = switch
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def run
|
48
|
+
@opts.parse!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
And then create a command to report something, offing `--dry-run' option:
|
53
|
+
|
54
|
+
# report.rb
|
55
|
+
require 'optparse/off'
|
56
|
+
require 'command'
|
57
|
+
|
58
|
+
# This class don't need `--dry-run' option
|
59
|
+
class Report < Command
|
60
|
+
def initialize
|
61
|
+
super
|
62
|
+
|
63
|
+
# Add an additional option specified to this command
|
64
|
+
@opts.on '--notifier=NOTIFIER', [:email, :irc, :and_so_on] do |notifier|
|
65
|
+
@notifier = notifiler
|
66
|
+
end
|
67
|
+
|
68
|
+
# Off the `--dry-run' option
|
69
|
+
@opts.off '--dry-run'
|
70
|
+
end
|
71
|
+
|
72
|
+
def run
|
73
|
+
super
|
74
|
+
# process reporting
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Contributing
|
79
|
+
------------
|
80
|
+
|
81
|
+
1. Fork it
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'test-unit'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'yard'
|
6
|
+
require "bundler/gem_tasks"
|
7
|
+
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
Rake::TestTask.new do |t|
|
11
|
+
t.loader = :direct
|
12
|
+
dir = File.dirname(__FILE__)
|
13
|
+
t.test_files = FileList["#{dir}/test/**/test*.rb"]
|
14
|
+
end
|
15
|
+
|
16
|
+
YARD::Rake::YardocTask.new
|
data/lib/optparse/off.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class OptionParser
|
4
|
+
def off(short_option=nil, long_option=nil)
|
5
|
+
sw = make_switch([short_option, long_option])
|
6
|
+
sw[1].each do |so|
|
7
|
+
top.short.delete so
|
8
|
+
end
|
9
|
+
sw[2].each do |lo|
|
10
|
+
top.long.delete lo
|
11
|
+
end
|
12
|
+
top.list.delete_if do |switch|
|
13
|
+
switch.short.delete short_option
|
14
|
+
switch.long.delete long_option
|
15
|
+
switch.short.empty? && switch.long.empty?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "optparse-off"
|
3
|
+
gem.version = '0.0.1'
|
4
|
+
gem.authors = ["KITAITI Makoto"]
|
5
|
+
gem.email = ["KitaitiMakoto@gmail.com"]
|
6
|
+
gem.description = %q{Add a functionality which remove options already added to OptionParser}
|
7
|
+
gem.summary = %q{Add removing-option functionality to OptionParser}
|
8
|
+
gem.homepage = ""
|
9
|
+
|
10
|
+
gem.files = %w[lib/optparse/off.rb test/test_off.rb README.markdown Rakefile LICENSE.txt optparse-off.gemspec]
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
end
|
data/test/test_off.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
gem 'test-unit'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'optparse/off'
|
4
|
+
|
5
|
+
class TestOptionParserOff < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@opt = OptionParser.new
|
8
|
+
end
|
9
|
+
|
10
|
+
data 'single short', {
|
11
|
+
:def_opts => %w[-n],
|
12
|
+
:off_opts => %w[-n],
|
13
|
+
:argv => %w[-n],
|
14
|
+
:expected => OptionParser::InvalidOption
|
15
|
+
}
|
16
|
+
data 'single short, single long, short arg', {
|
17
|
+
:def_opts => %w[-n --lines],
|
18
|
+
:off_opts => %w[-n],
|
19
|
+
:argv => %w[-n],
|
20
|
+
:expected => OptionParser::InvalidOption
|
21
|
+
}
|
22
|
+
data 'single short, single long, off short, long arg', {
|
23
|
+
:def_opts => %w[-n --lines],
|
24
|
+
:off_opts => %w[-n],
|
25
|
+
:argv => %w[--lines],
|
26
|
+
:expected => {'lines' => true}
|
27
|
+
}
|
28
|
+
data 'single short, single long, off short, short arg', {
|
29
|
+
:def_opts => %w[-n --lines],
|
30
|
+
:off_opts => %w[-n],
|
31
|
+
:argv => %w[-n],
|
32
|
+
:expected => OptionParser::InvalidOption
|
33
|
+
}
|
34
|
+
data 'single short, single long, off long, long arg', {
|
35
|
+
:def_opts => %w[-n --lines],
|
36
|
+
:off_opts => %w[--lines],
|
37
|
+
:argv => %w[--lines],
|
38
|
+
:expected => OptionParser::InvalidOption
|
39
|
+
}
|
40
|
+
data 'single short, single long, off both, long arg', {
|
41
|
+
:def_opts => %w[-n --lines],
|
42
|
+
:off_opts => %w[-n --lines],
|
43
|
+
:argv => %w[--lines],
|
44
|
+
:expected => OptionParser::InvalidOption
|
45
|
+
}
|
46
|
+
def test_opt_off(data)
|
47
|
+
@opt.def_option *data[:def_opts]
|
48
|
+
@opt.off *data[:off_opts]
|
49
|
+
if data[:expected].kind_of?(Class) and data[:expected] < Exception
|
50
|
+
assert_raise data[:expected] do
|
51
|
+
@opt.parse data[:argv]
|
52
|
+
end
|
53
|
+
else
|
54
|
+
assert_equal data[:expected], @opt.getopts(data[:argv])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: optparse-off
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- KITAITI Makoto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-12 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Add a functionality which remove options already added to OptionParser
|
15
|
+
email:
|
16
|
+
- KitaitiMakoto@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/optparse/off.rb
|
22
|
+
- test/test_off.rb
|
23
|
+
- README.markdown
|
24
|
+
- Rakefile
|
25
|
+
- LICENSE.txt
|
26
|
+
- optparse-off.gemspec
|
27
|
+
homepage: ''
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.8
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Add removing-option functionality to OptionParser
|
51
|
+
test_files:
|
52
|
+
- test/test_off.rb
|
53
|
+
has_rdoc:
|