slop 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +7 -0
- data/Rakefile +14 -14
- data/lib/slop.rb +14 -3
- data/slop.gemspec +1 -1
- data/test/slop_test.rb +9 -0
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
3.4.1 (2013-01-13)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Ensure options replace any existing duplicates
|
5
|
+
* Command config options now inherit config options from top level Slop.
|
6
|
+
* Command help output now adds command in usage string.
|
7
|
+
|
1
8
|
3.4.0 (2013-01-12)
|
2
9
|
------------------
|
3
10
|
|
data/Rakefile
CHANGED
@@ -10,20 +10,20 @@ Rake::TestTask.new do |t|
|
|
10
10
|
t.test_files = Dir['test/*_test.rb']
|
11
11
|
end
|
12
12
|
|
13
|
-
begin
|
14
|
-
|
13
|
+
# begin
|
14
|
+
# require 'rdoc/task'
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rescue LoadError
|
27
|
-
end
|
16
|
+
# # requires sdoc and horo gems
|
17
|
+
# RDoc::Task.new do |rdoc|
|
18
|
+
# rdoc.title = 'Slop API Documentation'
|
19
|
+
# rdoc.rdoc_dir = 'doc'
|
20
|
+
# rdoc.options << '-f' << 'sdoc'
|
21
|
+
# rdoc.options << '-T' << 'rails'
|
22
|
+
# rdoc.options << '-e' << 'UTF-8'
|
23
|
+
# rdoc.options << '-g'
|
24
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
# end
|
26
|
+
# rescue LoadError
|
27
|
+
# end
|
28
28
|
|
29
29
|
task :default => :test
|
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.4.
|
7
|
+
VERSION = '3.4.1'
|
8
8
|
|
9
9
|
# The main Error class, all Exception classes inherit from this class.
|
10
10
|
class Error < StandardError; end
|
@@ -131,6 +131,7 @@ class Slop
|
|
131
131
|
@callbacks = {}
|
132
132
|
@separators = {}
|
133
133
|
@runner = nil
|
134
|
+
@command = config.delete(:command)
|
134
135
|
|
135
136
|
if block_given?
|
136
137
|
block.arity == 1 ? yield(self) : instance_eval(&block)
|
@@ -191,7 +192,8 @@ class Slop
|
|
191
192
|
#
|
192
193
|
# Returns a new instance of Slop mapped to this command.
|
193
194
|
def command(command, options = {}, &block)
|
194
|
-
|
195
|
+
options = @config.merge(options)
|
196
|
+
@commands[command.to_s] = Slop.new(options.merge(:command => command.to_s), &block)
|
195
197
|
end
|
196
198
|
|
197
199
|
# Parse a list of items, executing and gathering options along the way.
|
@@ -261,6 +263,10 @@ class Slop
|
|
261
263
|
# Returns the created instance of Slop::Option.
|
262
264
|
def on(*objects, &block)
|
263
265
|
option = build_option(objects, &block)
|
266
|
+
original = options.find do |o|
|
267
|
+
o.long and o.long == option.long or o.short and o.short == option.short
|
268
|
+
end
|
269
|
+
options.delete(original) if original
|
264
270
|
options << option
|
265
271
|
option
|
266
272
|
end
|
@@ -426,7 +432,12 @@ class Slop
|
|
426
432
|
end
|
427
433
|
|
428
434
|
banner = config[:banner]
|
429
|
-
|
435
|
+
if banner.nil?
|
436
|
+
banner = "Usage: #{File.basename($0, '.*')}"
|
437
|
+
banner << " #{@command}" if @command
|
438
|
+
banner << " [command]" if @commands.any?
|
439
|
+
banner << " [options]"
|
440
|
+
end
|
430
441
|
if banner
|
431
442
|
"#{banner}\n#{@separators[0] ? "#{@separators[0]}\n" : ''}#{optstr}"
|
432
443
|
else
|
data/slop.gemspec
CHANGED
data/test/slop_test.rb
CHANGED
@@ -448,4 +448,13 @@ class SlopTest < TestCase
|
|
448
448
|
end
|
449
449
|
end
|
450
450
|
|
451
|
+
test "duplicate options should not exist, new options should replace old ones" do
|
452
|
+
i = nil
|
453
|
+
Slop.parse(%w'-v') do
|
454
|
+
on(:v) { i = 'first' }
|
455
|
+
on(:v) { i = 'second' }
|
456
|
+
end
|
457
|
+
assert_equal 'second', i
|
458
|
+
end
|
459
|
+
|
451
460
|
end
|
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.4.
|
4
|
+
version: 3.4.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: 2013-01-
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|