lib/asciidoctor/reducer/cli.rb in asciidoctor-reducer-1.0.0.alpha.6 vs lib/asciidoctor/reducer/cli.rb in asciidoctor-reducer-1.0.0.alpha.7
- old
+ new
@@ -1,13 +1,11 @@
# frozen_string_literal: true
+require_relative 'api'
autoload :OptionParser, 'optparse'
-autoload :Pathname, 'pathname'
module Asciidoctor::Reducer
- autoload :VERSION, (::File.join __dir__, 'version.rb')
-
class Cli
LOG_LEVELS = (::Logger::Severity.constants false).each_with_object({}) do |level, accum|
accum[level.to_s.downcase] = (::Logger::Severity.const_get level) unless level == :UNKNOWN
end
@@ -103,20 +101,12 @@
if (log_level = options.delete :log_level)
(options[:logger] = ::Asciidoctor::Logger.new $stderr).level = log_level
else
options[:logger] = nil
end
- if (output_file = options.delete :output_file) == '-'
- to = $stdout
- else
- (to = ::Pathname.new output_file).dirname.mkpath
- end
- if (input_file = options.delete :input_file) == '-'
- reduced = (::Asciidoctor.load $stdin, options).source + ?\n
- else
- reduced = (::Asciidoctor.load_file input_file, options).source + ?\n
- end
- ::Pathname === to ? (to.write reduced, encoding: ::Encoding::UTF_8) : (to.write reduced)
+ options[:to] = (output_file = options.delete :output_file) == '-' ? $stdout : (::Pathname.new output_file)
+ input = (input_file = options.delete :input_file) == '-' ? $stdin : (::Pathname.new input_file)
+ ::Asciidoctor::Reducer.reduce input, options
0
rescue
$stderr.write %(asciidoctor-reducer: #{$!.message}\n)
1
ensure