bin/review-compile in review-5.1.1 vs bin/review-compile in review-5.2.0

- old
+ new

@@ -14,10 +14,12 @@ require 'review' require 'fileutils' require 'optparse' require 'yaml' +include ReVIEW::Loggable + DEFAULT_CONFIG_FILENAME = 'config.yml'.freeze def main Signal.trap(:INT) { exit 1 } if RUBY_PLATFORM !~ /mswin(?!ce)|mingw|cygwin|bccwin/ @@ -45,21 +47,21 @@ parse_opts begin loader = ReVIEW::YAMLLoader.new if @config['yaml'] - error "#{@config['yaml']} not found." unless File.exist?(@config['yaml']) + error! "#{@config['yaml']} not found." unless File.exist?(@config['yaml']) begin @config.deep_merge!(loader.load_file(@config['yaml'])) rescue => e - error "yaml error #{e.message}" + error! "yaml error #{e.message}" end elsif File.exist?(DEFAULT_CONFIG_FILENAME) begin @config.deep_merge!(loader.load_file(DEFAULT_CONFIG_FILENAME)) rescue => e - error "yaml error #{e.message}" + error! "yaml error #{e.message}" end end @config['builder'] = @target ReVIEW::I18n.setup(@config['language']) @@ -71,16 +73,16 @@ @mode = :dir if ARGV.blank? case @mode when :files - error('no input') if ARGV.empty? + error!('no input') if ARGV.empty? @basedir = File.dirname(ARGV[0]) book = ReVIEW::Book::Base.new(@basedir, config: @config) ARGV.each do |item| - error("file not found: #{item}") unless File.exist?(File.join(book.config['contentdir'], item)) + error!("file not found: #{item}") unless File.exist?(File.join(book.config['contentdir'], item)) chap_name = File.basename(item, '.*') chap = book.chapter(chap_name) compiler = ReVIEW::Compiler.new(load_builder_class(@target, @check_only)) result = compiler.compile(chap) if @output_filename @@ -103,11 +105,11 @@ end else raise "must not happen: #{@mode}" end rescue ReVIEW::ApplicationError => e - error(e.message) + error! e.message end end def parse_opts opts = OptionParser.new @@ -160,18 +162,9 @@ rescue OptionParser::ParseError => e warn(e.message) $stderr.puts opts.help exit 1 end -end - -def error(msg) - @logger.error msg - exit 1 -end - -def warn(msg) - @logger.warn msg end def load_builder_class(target, strict) require "review/#{target}builder" ReVIEW.const_get("#{target.upcase}Builder").new(strict)