Sha256: 94eb636bf14738c67ddf503da2a874c58f1b368dd3a00920c9c53a7f246c173a

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

require 'trollop'

module Stackster
  module CLI
    def self.start
      @opts = Trollop::options do
        banner <<-EOS
build and manage stacks
EOS
        opt :help, "Display Help"
        opt :attributes, "CSV list of = seperated attributes to set", :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

      case @cmd
      when 'create', 'destroy', 'delete', 'list', 'update'
        unless EnvironmentLister.all.include? @opts[:environment]
          puts "Please specify a valid environment: #{EnvironmentLister.all}"
          exit 1
        end
        @s = Stack.new :environment => @opts[:environment],
                       :name => @opts[:name]
      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 'environments'
        puts EnvironmentLister.all
      when 'show'
        sf = StackFormater.new :environment => @opts[:environment],
                               :name => @opts[:name]
        puts sf.display.to_yaml
      when 'list'
        s = StackLister.new @opts[:environment]
        puts s.all
      else
        puts "Unkown command '#{@cmd}'"
      end
    end

    def self.attributes
      attrs = []
      read_attributes.each do |attribs|
        a = attribs.split('=')
        attrs << { a.first => a.last }
      end
      attrs
    end

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stackster-0.0.2 lib/stackster/cli.rb