diff --git a/lib/consult.rb b/lib/consult.rb index 7c46176..e5cd80c 100644 --- a/lib/consult.rb +++ b/lib/consult.rb @@ -20,7 +20,7 @@ module Consult class << self attr_reader :config, :templates, :force_render - def load(config_dir: nil, force_render: false, verbose: nil) + def load(config_dir: nil, force_render: false, raise_on_error: false, verbose: nil) root directory: config_dir yaml = root.join('config', 'consult.yml') diff --git a/lib/consult/cli.rb b/lib/consult/cli.rb index 54f57d1..a243352 100644 --- a/lib/consult/cli.rb +++ b/lib/consult/cli.rb @@ -26,6 +26,7 @@ def parse_options(argv) opts = { config_dir: Dir.pwd, force_render: true, + raise_on_error: false, verbose: true } @@ -38,6 +39,10 @@ def parse_options(argv) opts[:force_render] = arg end + o.on '--raise-on-error', FalseClass, 'Raise errors instead of printing them' do |arg| + opts[:raise_on_error] = arg + end + o.on '--quiet', FalseClass, 'Silence output' do |arg| opts[:verbose] = arg end diff --git a/lib/consult/template.rb b/lib/consult/template.rb index 29ba67f..7672418 100644 --- a/lib/consult/template.rb +++ b/lib/consult/template.rb @@ -37,6 +37,11 @@ def render(save: true) result rescue StandardError => e STDERR.puts "Error rendering template: #{name}" + + if @config[:raise_on_error] + raise e + end + STDERR.puts e STDERR.puts e.backtrace if verbose? nil