lib/bora/cli.rb in bora-1.0.1 vs lib/bora/cli.rb in bora-1.1.0

- old
+ new

@@ -1,24 +1,35 @@ require "thor" require "bora" class Bora class Cli < Thor - class_option :file, type: :string, aliases: :f, default: Bora::DEFAULT_CONFIG_FILE, desc: "The Bora config file to use" + class_option :file, + type: :string, + aliases: :f, + default: Bora::DEFAULT_CONFIG_FILE, + desc: "The Bora config file to use" + class_option :region, + type: :string, + aliases: :r, + default: nil, + desc: "The region to use for the stack operation. Overrides any regions specified in the Bora config file." + desc "list", "Lists the available stacks" def list templates = bora(options.file).templates stacks = templates.collect { |t| t.stacks }.flatten stack_names = stacks.collect { |s| s.stack_name } puts stack_names.join("\n") end desc "apply STACK_NAME", "Creates or updates the stack" option :params, type: :array, aliases: :p, desc: "Parameters to be passed to the template, eg: --params 'instance_type=t2.micro'" + option :pretty, type: :boolean, default: false, desc: "Send pretty (formatted) JSON to AWS (only works for cfndsl templates)" def apply(stack_name) - stack(options.file, stack_name).apply(params) + stack(options.file, stack_name).apply(params, options.pretty) end desc "delete STACK_NAME", "Deletes the stack" def delete(stack_name) stack(options.file, stack_name).delete @@ -70,20 +81,22 @@ private def stack(config_file, stack_name) - bora = bora(config_file) + region = options.region + override_config = region ? {"default_region" => region} : {} + bora = bora(config_file, override_config) stack = bora.stack(stack_name) if !stack STDERR.puts "Could not find stack #{stack_name}" exit(1) end stack end - def bora(config_file) - Bora.new(config_file_or_hash: config_file) + def bora(config_file, override_config = {}) + Bora.new(config_file_or_hash: config_file, override_config: override_config) end def params options.params ? Hash[options.params.map { |param| param.split("=", 2) }] : {} end