diff --git a/lib/bolognese/cli.rb b/lib/bolognese/cli.rb index 7d6bae50..1f0eeed8 100644 --- a/lib/bolognese/cli.rb +++ b/lib/bolognese/cli.rb @@ -29,7 +29,7 @@ def __print_version method_option :regenerate, :type => :boolean, :force => false method_option :style, aliases: "-s", default: "apa" method_option :locale, aliases: "-l", default: "en-US" - method_option :ignore_errors, aliases: "-e", default: nil + method_option :show_errors, :type => :boolean, :force => false def convert(input) metadata = Metadata.new(input: input, from: options[:from], @@ -38,10 +38,10 @@ def convert(input) locale: options[:locale]) to = options[:to] || "schema_org" - if metadata.valid? || options[:ignore_errors] - puts metadata.send(to) - else + if options[:show_errors] && !metadata.valid? $stderr.puts metadata.errors + else + puts metadata.send(to) end end diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 7603d13c..717c6336 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -180,13 +180,13 @@ it 'to datacite invalid' do file = fixture_path + "datacite_missing_creator.xml" - subject.options = { to: "datacite" } + subject.options = { to: "datacite", show_errors: "true" } expect { subject.convert file }.to output("4:0: ERROR: Element '{http://datacite.org/schema/kernel-4}creators': Missing child element(s). Expected is ( {http://datacite.org/schema/kernel-4}creator ).\n").to_stderr end it 'to datacite invalid ignore errors' do file = fixture_path + "datacite_missing_creator.xml" - subject.options = { to: "datacite", ignore_errors: "true" } + subject.options = { to: "datacite" } expect { subject.convert file }.to output(/http:\/\/datacite.org\/schema\/kernel-4/).to_stdout end end