Sha256: 0ed3f00158b765ca61616a73b875c34bf7c674f3a0510f38fc21fec000e6988b

Contents?: true

Size: 1.39 KB

Versions: 200

Compression:

Stored size: 1.39 KB

Contents

require 'dpl/error'
require 'dpl/provider'

module DPL
  class CLI
    def self.run(*args)
      new(args).run
    end

    OPTION_PATTERN = /\A--([a-z][a-z_\-]*)(?:=(.+))?\z/
    attr_accessor :options, :fold_count

    def initialize(*args)
      options = {}
      args.flatten.each do |arg|
        next options.update(arg) if arg.is_a? Hash
        die("invalid option %p" % arg) unless match = OPTION_PATTERN.match(arg)
        key = match[1].tr('-', '_').to_sym
        if options.include? key
          options[key] = Array(options[key]) << match[2]
        else
          options[key] = match[2] || true
        end
      end

      self.fold_count = 0
      self.options    = default_options.merge(options)
    end

    def run
      provider = Provider.new(self, options)
      provider.deploy
    rescue Error => error
      options[:debug] ? raise(error) : die(error.message)
    end

    def fold(message)
      self.fold_count += 1
      print "travis_fold:start:dpl.#{fold_count}\r" if options[:fold]
      puts "\e[33m#{message}\e[0m"
      yield
    ensure
      print "\ntravis_fold:end:dpl.#{fold_count}\r" if options[:fold]
    end

    def default_options
      {
        :app      => File.basename(Dir.pwd),
        :key_name => %x[hostname].strip
      }
    end

    def shell(command)
      system(command)
    end

    def die(message)
      $stderr.puts(message)
      exit 1
    end
  end
end

Version data entries

200 entries across 200 versions & 1 rubygems

Version Path
dpl-1.4.6.travis.119.2 lib/dpl/cli.rb
dpl-1.4.6.travis.118.4 lib/dpl/cli.rb
dpl-1.4.6.travis.117.3 lib/dpl/cli.rb
dpl-1.4.6.travis.117.4 lib/dpl/cli.rb
dpl-1.4.6.travis.117.6 lib/dpl/cli.rb
dpl-1.4.6.travis.117.5 lib/dpl/cli.rb
dpl-1.4.6.travis.117.1 lib/dpl/cli.rb
dpl-1.4.6.travis.116.4 lib/dpl/cli.rb
dpl-1.4.5 lib/dpl/cli.rb
dpl-1.4.4 lib/dpl/cli.rb
dpl-1.4.3 lib/dpl/cli.rb
dpl-1.4.2 lib/dpl/cli.rb
dpl-1.4.1 lib/dpl/cli.rb
dpl-1.4.0 lib/dpl/cli.rb
dpl-1.3.4 lib/dpl/cli.rb
dpl-1.3.3 lib/dpl/cli.rb
dpl-1.3.2 lib/dpl/cli.rb
dpl-1.3.1 lib/dpl/cli.rb
dpl-1.3.0 lib/dpl/cli.rb
dpl-1.2.0 lib/dpl/cli.rb