Module: SimpleDeploy::CLI

Defined in:
lib/simple_deploy/cli.rb,
lib/simple_deploy/cli/variables.rb

Class Method Summary collapse

Class Method Details

.attributesObject



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/simple_deploy/cli/variables.rb', line 3

def self.attributes
  attrs = []
  puts "Read the following attributes:"
  read_attributes.each do |attribs|
    key = attribs.split('=').first.gsub(/\s+/, "")
    value = attribs.gsub(/^.+?=/, '')
    puts "#{key} : #{value}"
    attrs << { key => value }
  end
  attrs
end

.environment_provided?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/simple_deploy/cli/variables.rb', line 19

def self.environment_provided?
  @opts[:environment].nil? != true
end

.read_attributesObject



15
16
17
# File 'lib/simple_deploy/cli/variables.rb', line 15

def self.read_attributes
  @opts[:attributes].nil? ? [] :  @opts[:attributes].split(',')
end

.startObject



6
7
8
9
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/simple_deploy/cli.rb', line 6

def self.start
  @opts = Trollop::options do
    banner <<-EOS

Deploy and manage resources in AWS

simple_deploy environments
simple_deploy list -e ENVIRONMENT
simple_deploy create -n STACK_NAME -e ENVIRONMENT -a ATTRIBUTES -t TEMPLATE_PATH
simple_deploy update -n STACK_NAME -e ENVIRONMENT -a ATTRIBUTES
simple_deploy deploy -n STACK_NAME -e ENVIRONMENT
simple_deploy destroy -n STACK_NAME -e ENVIRONMENT
simple_deploy instances -n STACK_NAME -e ENVIRONMENT
simple_deploy status -n STACK_NAME -e ENVIRONMENT
simple_deploy attributes -n STACK_NAME -e ENVIRONMENT
simple_deploy events -n STACK_NAME -e ENVIRONMENT
simple_deploy resources -n STACK_NAME -e ENVIRONMENT
simple_deploy outputs -n STACK_NAME -e ENVIRONMENT
simple_deploy template -n STACK_NAME -e ENVIRONMENT

EOS
    opt :help, "Display Help"
    opt :attributes, "CSV list of updates attributes", :type => :string
    opt :environment, "Set the target environment", :type => :string
    opt :name, "Stack name to manage", :type => :string
    opt :template, "Path to the template file", :type => :string
  end

  @cmd = ARGV.shift

  unless @cmd
    puts "Please specify a command."
    exit 1
  end

  read_attributes
  
  unless @cmd == 'environments'
    @config = Config.new.environment @opts[:environment]

    unless environment_provided?
      puts "Please specify an environment."
      Config.new.environments.keys.each { |e| puts e }
      exit 1
    end
  end

  case @cmd
  when 'create', 'delete', 'deploy', 'destroy', 'instances',
       'status', 'attributes', 'events', 'resources',
       'outputs', 'template', 'update'
    @stack = Stack.new :environment => @opts[:environment],
                       :name        => @opts[:name],
                       :config      => @config
  end

  case @cmd
  when 'attributes'
    @stack.attributes.each_pair { |k, v| puts "#{k}: #{v}" }
  when 'create'
    @stack.create :attributes => attributes,
                  :template => @opts[:template]
    puts "#{@opts[:name]} created."
  when 'delete', 'destroy'
    @stack.destroy
    puts "#{@opts[:name]} destroyed."
  when 'deploy'
    @stack.deploy
    puts "#{@opts[:name]} deployed."
  when 'environments'
    Config.new.environments.keys.each { |e| puts e }
  when 'update'
    @stack.update :attributes => attributes
    puts "#{@opts[:name]} updated."
  when 'instances'
    @stack.instances.each { |s| puts s }
  when 'list'
    puts Stack.list(:config => @config)
  when 'template'
    jj @stack.template
  when 'events', 'outputs', 'resources', 'status'
    puts (@stack.send @cmd.to_sym).to_yaml
  else
    puts "Unknown command.  Use -h for help."
  end
end