summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2014-08-04 02:04:11 -0600
committerDan Allen <dan.j.allen@gmail.com>2014-08-04 02:04:11 -0600
commit3cf3fc89c890a0ba4abdaf2bd3738c6abf1555d3 (patch)
tree4f4411a3cd1ab9ba64df87638aa814a523febd99
parentbcea069341bc19e2068df485efc2ac764b7d1baa (diff)
follow-up to #574 support multiple values in single -r or -I flag
-rw-r--r--lib/asciidoctor/cli/options.rb8
-rw-r--r--test/options_test.rb29
2 files changed, 31 insertions, 6 deletions
diff --git a/lib/asciidoctor/cli/options.rb b/lib/asciidoctor/cli/options.rb
index 085cc89d..0e523e59 100644
--- a/lib/asciidoctor/cli/options.rb
+++ b/lib/asciidoctor/cli/options.rb
@@ -109,11 +109,11 @@ Example: asciidoctor -b html5 source.asciidoc
end
opts.on('-IDIRECTORY', '--load-path LIBRARY', 'add a directory to the $LOAD_PATH',
'may be specified more than once') do |path|
- (self[:load_paths] ||= []) << path
+ (self[:load_paths] ||= []).concat(path.split ::File::PATH_SEPARATOR)
end
opts.on('-rLIBRARY', '--require LIBRARY', 'require the specified library before executing the processor (using require)',
'may be specified more than once') do |path|
- (self[:requires] ||= []) << path
+ (self[:requires] ||= []).concat(path.split ',')
end
opts.on('-q', '--quiet', 'suppress warnings (default: false)') do |verbose|
self[:verbose] = 0
@@ -208,13 +208,13 @@ Example: asciidoctor -b html5 source.asciidoc
end
if (load_paths = self[:load_paths])
- load_paths.reverse_each do |path|
+ (self[:load_paths] = load_paths.uniq).reverse_each do |path|
$:.unshift File.expand_path(path)
end
end
if (requires = self[:requires])
- requires.each do |path|
+ (self[:requires] = requires.uniq).each do |path|
begin
require path
rescue ::LoadError
diff --git a/test/options_test.rb b/test/options_test.rb
index 7e7c37c4..769fe037 100644
--- a/test/options_test.rb
+++ b/test/options_test.rb
@@ -112,7 +112,7 @@ context 'Options' do
assert_equal ['custom-backend', 'custom-backend-hacks'], options[:template_dirs]
end
- test '-r option requires specified libraries' do
+ test 'multiple -r flags requires specified libraries' do
options = Asciidoctor::Cli::Options.new
redirect_streams do |stdout, stderr|
exitval = options.parse! %w(-r foobar -r foobaz test/fixtures/sample.asciidoc)
@@ -122,7 +122,17 @@ context 'Options' do
end
end
- test '-I option appends directories to $LOAD_PATH' do
+ test '-r flag with multiple values requires specified libraries' do
+ options = Asciidoctor::Cli::Options.new
+ redirect_streams do |stdout, stderr|
+ exitval = options.parse! %w(-r foobar,foobaz test/fixtures/sample.asciidoc)
+ assert_match(%(asciidoctor: FAILED: 'foobar' could not be loaded), stderr.string)
+ assert_equal 1, exitval
+ assert_equal ['foobar', 'foobaz'], options[:requires]
+ end
+ end
+
+ test '-I option appends paths to $LOAD_PATH' do
options = Asciidoctor::Cli::Options.new
old_load_path = $LOAD_PATH.dup
begin
@@ -137,6 +147,21 @@ context 'Options' do
end
end
+ test '-I option appends multiple paths to $LOAD_PATH' do
+ options = Asciidoctor::Cli::Options.new
+ old_load_path = $LOAD_PATH.dup
+ begin
+ exitval = options.parse! %W(-I foobar#{File::PATH_SEPARATOR}foobaz test/fixtures/sample.asciidoc)
+ refute_equal 1, exitval
+ assert_equal old_load_path.size + 2, $LOAD_PATH.size
+ assert_equal File.expand_path('foobar'), $LOAD_PATH[0]
+ assert_equal File.expand_path('foobaz'), $LOAD_PATH[1]
+ assert_equal ['foobar', 'foobaz'], options[:load_paths]
+ ensure
+ ($LOAD_PATH.size - old_load_path.size).times { $LOAD_PATH.shift }
+ end
+ end
+
test 'should set verbose to 2 when -v flag is specified' do
options = Asciidoctor::Cli::Options.parse!(%w(-v test/fixtures/sample.asciidoc))
assert_equal 2, options[:verbose]