Sha256: f694737f4c2f1dead644754ef151f14b066bc78ee5778f0a63bbee549c83f8d8

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

require 'trollop'

module Stackster
  module CLI
    def self.start
      @opts = Trollop::options do
        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

EOS
        opt :help, "Display Help"
        opt :attributes, "CSV list of = seperated attributes to set", :type => :string
        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],
                       :config => nil
      end

      read_attributes

      case @cmd
      when 'create'
        @s.create :attributes => attributes,
                  :template => @opts[:template]
        puts "#{@opts[:name]} created."
      when 'update'
        @s.update :attributes => attributes
        puts "#{@opts[:name]} updated."
      when 'destroy', 'delete'
        @s.destroy
        puts "#{@opts[:name]} destroyed."
      when 'show'
        puts @s.display.to_yaml
      when 'list'
        puts Stack.list(:config => nil)
      else
        puts "Unkown command '#{@cmd}'"
      end
    end

    def self.attributes
      attrs = []
      read_attributes.each do |attribs|
        a = attribs.split('=')
        attrs << { a.first.gsub(/\s+/, "") => a.last }
      end
      attrs
    end

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stackster-0.1.3 lib/stackster/cli.rb
stackster-0.1.2 lib/stackster/cli.rb
stackster-0.1.1 lib/stackster/cli.rb