lib/asciidoctor/cli/invoker.rb in asciidoctor-1.5.8 vs lib/asciidoctor/cli/invoker.rb in asciidoctor-2.0.0.rc.1
- old
+ new
@@ -1,10 +1,11 @@
-# encoding: UTF-8
+# frozen_string_literal: true
module Asciidoctor
module Cli
# Public Invocation class for starting Asciidoctor via CLI
class Invoker
+ include Logging
attr_reader :options
attr_reader :documents
attr_reader :code
@@ -30,12 +31,12 @@
end
def invoke!
return unless @options
- old_verbose = $VERBOSE
old_logger = old_logger_level = nil
+ old_verbose, $VERBOSE = $VERBOSE, @options[:warnings]
opts = {}
infiles = []
outfile = nil
abs_srcdir_posix = nil
non_posix_env = ::File::ALT_SEPARATOR == RS
@@ -59,22 +60,18 @@
# NOTE processor will dup attributes internally
opts[:attributes] = val
when :timings
show_timings = val
when :trace
- # currently does nothing
+ # no assignment
when :verbose
case val
when 0
$VERBOSE = nil
- old_logger = LoggerManager.logger
- LoggerManager.logger = NullLogger.new
- when 1
- $VERBOSE = false
+ old_logger, LoggerManager.logger = logger, NullLogger.new
when 2
- $VERBOSE = true
- old_logger_level, LoggerManager.logger.level = LoggerManager.logger.level, ::Logger::Severity::DEBUG
+ old_logger_level, logger.level = logger.level, ::Logger::Severity::DEBUG
end
else
opts[key] = val unless val.nil?
end
end
@@ -99,20 +96,20 @@
end
if stdin
# allows use of block to supply stdin, particularly useful for tests
input = block_given? ? yield : STDIN
- input_opts = opts.merge :to_file => tofile
+ input_opts = opts.merge to_file: tofile
if show_timings
- @documents << (::Asciidoctor.convert input, (input_opts.merge :timings => (timings = Timings.new)))
+ @documents << (::Asciidoctor.convert input, (input_opts.merge timings: (timings = Timings.new)))
timings.print_report err, '-'
else
@documents << (::Asciidoctor.convert input, input_opts)
end
else
infiles.each do |infile|
- input_opts = opts.merge :to_file => tofile
+ input_opts = opts.merge to_file: tofile
if abs_srcdir_posix && (input_opts.key? :to_dir)
abs_indir = ::File.dirname ::File.expand_path infile
if non_posix_env
abs_indir_posix = (abs_indir.include? RS) ? (abs_indir.tr RS, FS) : abs_indir
else
@@ -121,42 +118,38 @@
if abs_indir_posix.start_with? %(#{abs_srcdir_posix}/)
input_opts[:to_dir] += abs_indir.slice abs_srcdir_posix.length, abs_indir.length
end
end
if show_timings
- @documents << (::Asciidoctor.convert_file infile, (input_opts.merge :timings => (timings = Timings.new)))
+ @documents << (::Asciidoctor.convert_file infile, (input_opts.merge timings: (timings = Timings.new)))
timings.print_report err, infile
else
@documents << (::Asciidoctor.convert_file infile, input_opts)
end
end
end
- @code = 1 if ((logger = LoggerManager.logger).respond_to? :max_severity) && logger.max_severity && logger.max_severity >= opts[:failure_level]
+ @code = 1 if (logger.respond_to? :max_severity) && logger.max_severity && logger.max_severity >= opts[:failure_level]
rescue ::Exception => e
if ::SignalException === e
@code = e.signo
- # add extra endline if Ctrl+C is used
+ # add extra newline if Ctrl+C is used
err.puts if ::Interrupt === e
else
@code = (e.respond_to? :status) ? e.status : 1
if @options[:trace]
raise e
else
- if ::RuntimeError === e
- err.puts %(#{e.message} (#{e.class}))
- else
- err.puts e.message
- end
+ err.puts ::RuntimeError === e ? %(#{e.message} (#{e.class})) : e.message
err.puts ' Use --trace for backtrace'
end
end
nil
ensure
$VERBOSE = old_verbose
if old_logger
LoggerManager.logger = old_logger
elsif old_logger_level
- LoggerManager.logger.level = old_logger_level
+ logger.level = old_logger_level
end
end
def document
@documents[0]