Class: SimpleDeploy::CLI::Clone

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/simple_deploy/cli/clone.rb

Instance Method Summary collapse

Methods included from Shared

#command_name, #parse_attributes, #rescue_stackster_exceptions_and_exit, #valid_options?

Instance Method Details

#cloneObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/simple_deploy/cli/clone.rb', line 10

def clone
  @opts = Trollop::options do
    version SimpleDeploy::VERSION
    banner <<-EOS

Clone a stack.

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

  valid_options? :provided => @opts,
                 :required => [:environment, :source_name, :new_name]

  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

  if @opts[:template]
    template_file = @opts[:template]
  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

  rescue_stackster_exceptions_and_exit do
    new_stack.create :attributes => new_attributes,
                     :template   => template_file
  end
end

#command_summaryObject



53
54
55
# File 'lib/simple_deploy/cli/clone.rb', line 53

def command_summary
  'Clone a stack'
end