Skip to content

Commit

Permalink
Merge pull request #46 from aibou/feature/check-template-arguments
Browse files Browse the repository at this point in the history
Implement 'required' method using in template and '--show-backtrace' option
  • Loading branch information
aibou authored Jul 30, 2019
2 parents 3a7ea48 + d133fa5 commit cfdb448
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bin/miam
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.map(&:to_s) - @context.keys.map(&:to_s)
unless missing_args.empty?
ex = ArgumentError.new("Missing arguments: [#{missing_args.join(", ")}] in template: '#{@template_name}'")
ex.set_backtrace(@caller)
raise ex
end
end
end
end

0 comments on commit cfdb448

Please sign in to comment.