Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config & CLI option for "raise on error" #49

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/consult.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 5 additions & 0 deletions lib/consult/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def parse_options(argv)
opts = {
config_dir: Dir.pwd,
force_render: true,
raise_on_error: false,
verbose: true
}

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/consult/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down