Skip to content
Permalink
Browse files

Implement '--show-backtrace' option and 'required' method using in te…

…mplate
  • Loading branch information...
aibou committed Jul 25, 2019
1 parent 3a7ea48 commit ac2bb2c3615d6d96d41190d6b224f98de055f55b
Showing with 18 additions and 4 deletions.
  1. +7 −4 bin/miam
  2. +11 −0 lib/miam/template_helper.rb
@@ -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)
@@ -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 = {}
@@ -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
@@ -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
@@ -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.
You can’t perform that action at this time.