lib/simple_deploy/cli/clone.rb in simple_deploy-0.6.4 vs lib/simple_deploy/cli/clone.rb in simple_deploy-0.6.5
- old
+ new
@@ -1,11 +1,14 @@
require 'trollop'
require 'tempfile'
module SimpleDeploy
module CLI
+
class Clone
+ include Shared
+
def clone
@opts = Trollop::options do
version SimpleDeploy::VERSION
banner <<-EOS
@@ -14,22 +17,23 @@
simple_deploy clone -s SOURCE_STACK_NAME -n NEW_STACK_NAME -e ENVIRONMENT -a ATTRIB1=VALUE -a ATTRIB2=VALUE
EOS
opt :help, "Display Help"
opt :environment, "Set the target environment", :type => :string
+ opt :log_level, "Log level: debug, info, warn, error", :type => :string,
+ :default => 'info'
opt :source_name, "Stack name for the stack to clone", :type => :string
opt :new_name, "Stack name for the new stack", :type => :string
opt :attributes, "= separated attribute and it's value", :type => :string,
:multi => true
opt :template, "Path to a new template file", :type => :string
end
- CLI::Shared.valid_options? :provided => @opts,
- :required => [:environment, :source_name, :new_name]
+ valid_options? :provided => @opts,
+ :required => [:environment, :source_name, :new_name]
- override_attributes = CLI::Shared.parse_attributes :attributes => @opts[:attributes],
- :logger => logger
+ override_attributes = parse_attributes :attributes => @opts[:attributes]
cloned_attributes = filter_attributes source_stack.attributes
new_attributes = merge_attributes cloned_attributes, override_attributes
new_attributes += add_attributes cloned_attributes, override_attributes
@@ -38,16 +42,21 @@
else
template_file = Tempfile.new("#{@opts[:new_name]}_template.json").path
File::open(template_file, 'w') { |f| f.write source_stack.template.to_json }
end
- new_stack.create :attributes => new_attributes,
- :template => template_file
+ rescue_stackster_exceptions_and_exit do
+ new_stack.create :attributes => new_attributes,
+ :template => template_file
+ end
end
- private
+ def command_summary
+ 'Clone a stack'
+ end
+ private
def filter_attributes(source_attributes)
selected = source_attributes.select { |k| k !~ /^deployment/ }
selected.map { |k,v| { k => v } }
end
@@ -86,8 +95,10 @@
@new_stack ||= Stack.new :environment => @opts[:environment],
:name => @opts[:new_name],
:config => config,
:logger => logger
end
+
end
+
end
end