Sha256: 397d4495e5f375b5deedf8e2c21b70a2e173d824d5b1d27baa2ea3f98aa08381

Contents?: true

Size: 1.42 KB

Versions: 526

Compression:

Stored size: 1.42 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

    def env
      ENV
    end
  end
end

Version data entries

526 entries across 526 versions & 4 rubygems

Version Path
dpl-1.10.17.travis.6637.6 lib/dpl/cli.rb
dpl-1.10.16 lib/dpl/cli.rb
dpl-1.10.16.travis.6625.6 lib/dpl/cli.rb
dpl-1.10.16.travis.6619.6 lib/dpl/cli.rb
dpl-1.10.16.travis.5961.5 lib/dpl/cli.rb
dpl-1.10.15 lib/dpl/cli.rb
dpl-1.10.15.travis.5877.5 lib/dpl/cli.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
dpl-1.10.14 lib/dpl/cli.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
dpl-1.10.13 lib/dpl/cli.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb
dpl-1.10.13.travis.4159.5 lib/dpl/cli.rb
dpl-1.10.13.travis.4141.5 lib/dpl/cli.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/dpl-1.10.12/lib/dpl/cli.rb