Sha256: ed86dc528d8e4f7ef0aeb274e16cc0ebadc9fecf0c030527a3c447471db9744f

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true
require "bundler"
require "English"

module KapostDeploy
  module Heroku
    # Wraps the heroku shell environment
    # Derived from https://github.com/fastestforward/heroku_san
    class Shell
      def initialize(app)
        self.app = app
      end

      def run(command)
        sh("run " + command)
      end

      def sh(command)
        preflight_check_for_cli

        cmd = command.split(" ")
        cmd += ["--app", app]
        cmd << "--exit-code" if command =~ /^run/

        show_command = cmd.join(" ")
        ok = ::Bundler.with_clean_env { system "heroku", *cmd }

        ok or fail "Command failed with status (#{$CHILD_STATUS.exitstatus}): [heroku #{show_command}]"
      end

      private

      attr_accessor :app

      def preflight_check_for_cli
        if Bundler.with_clean_env { system("heroku version").nil? }
          fail "The Heroku Toolbelt is required for this action. http://toolbelt.heroku.com"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kapost_deploy-0.2.0 lib/kapost_deploy/heroku/shell.rb