Module: Stackster::CLI

Defined in:
lib/stackster/cli.rb

Class Method Summary collapse

Class Method Details

.startObject



5
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
# File 'lib/stackster/cli.rb', line 5

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

I build and manage AWS Cloud Formation Stacks

stackster list 
stackster create -n STACK_NAME -a ATTRIBUTES -t TEMPLATE_PATH
stackster update -n STACK_NAME -a ATTRIBUTES
stackster show -n STACK_NAME
stackster destroy -n STACK_NAME

Attributes are specified as '=' seperated key value pairs.  Multiple can be specified.  For example:

stackster create -n test-stack -t ~/my-template.json -a arg1=val1 -a arg2=vol2
EOS
    opt :help, "Display Help"
    opt :attributes, "= seperated attribute and it's value", :type  => :string,
                                                              :multi => true
    opt :log_level, "Log level:  debug, info, warn, error", :type    => :string,
                                                            :default => 'info'
    opt :name, "Stack name to manage", :type => :string
    opt :template, "Path to the template file", :type => :string
  end

  @cmd = ARGV.shift

  case @cmd
  when 'create', 'destroy', 'delete', 'list', 'update', 'show'
    @s = Stack.new :name => @opts[:name],
                   :logger => StacksterLogger.new(:log_level => @opts[:log_level])
  end

  case @cmd
  when 'create'
    @s.create :attributes => attributes,
              :template => @opts[:template]
  when 'update'
    @s.update :attributes => attributes
  when 'destroy', 'delete'
    @s.destroy
  when 'show'
    puts @s.display.to_yaml
  when 'list'
    puts StackLister.new.all.sort
  else
    puts "Unkown command '#{@cmd}'"
  end
end