Skip to content

Commit

Permalink
Implement '--show-backtrace' option and 'required' method using in te…
Browse files Browse the repository at this point in the history
…mplate
  • Loading branch information
aibou committed Jul 25, 2019
1 parent 3a7ea48 commit ac2bb2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bin/miam
Expand Up @@ -19,10 +19,11 @@ MAGIC_COMMENT = <<-EOS
EOS

options = {
:dry_run => false,
:format => :ruby,
:color => true,
:debug => false,
:dry_run => false,
:format => :ruby,
:color => true,
:debug => false,
:show_backtrace => false
}

options[:password_manager] = Miam::PasswordManager.new(account_output, options)
Expand Down Expand Up @@ -58,6 +59,7 @@ ARGV.options do |opt|
opt.on('' , '--no-color') { options[:color] = false }
opt.on('' , '--no-progress') { options[:no_progress] = true }
opt.on('' , '--debug') { options[:debug] = true }
opt.on('' , '--show-backtrace') { options[:show_backtrace] = true }
opt.parse!

aws_opts = {}
Expand Down Expand Up @@ -186,6 +188,7 @@ rescue => e
raise e
else
$stderr.puts("[ERROR] #{e.message}".red)
$stderr.puts(e.backtrace.map(&:yellow)) if options[:show_backtrace]
exit 1
end
end
11 changes: 11 additions & 0 deletions lib/miam/template_helper.rb
@@ -1,6 +1,8 @@
module Miam
module TemplateHelper
def include_template(template_name, context = {})
@template_name = template_name
@caller = caller[0]
tmplt = @context.templates[template_name.to_s]

unless tmplt
Expand All @@ -16,5 +18,14 @@ def include_template(template_name, context = {})
def context
@context
end

def required(*args)
missing_args = args - @context.keys
unless missing_args.empty?
ex = ArgumentError.new("Missing arguments: #{missing_args.join(", ")} in '#{@template_name}'")
ex.set_backtrace(@caller)
raise ex
end
end
end
end

0 comments on commit ac2bb2c

Please sign in to comment.