Sha256: 87dca29a336259f973ba296298c681e1c79bb381d0eb7dc6d744a671e975faf0

Contents?: true

Size: 1.01 KB

Versions: 19

Compression:

Stored size: 1.01 KB

Contents

require 'aptible/api'
require 'git'

module Aptible
  module CLI
    module Helpers
      module App
        include Helpers::Token

        def ensure_app(options = {})
          handle = options[:app] || ensure_default_handle
          app = app_from_handle(handle)
          return app if app
          fail Thor::Error, "Could not find app #{handle}"
        end

        def app_from_handle(handle)
          Aptible::Api::App.all(token: fetch_token).find do |a|
            a.handle == handle
          end
        end

        def ensure_default_handle
          return default_handle if default_handle
          fail Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
            Could not find app in current working directory, please specify
            with --app
          ERR
        end

        def default_handle
          git = Git.open(Dir.pwd)
          aptible_remote = git.remote(:aptible).url || ''
          aptible_remote[/:(?<name>.+)\.git/, :name]
        rescue
          nil
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
aptible-cli-0.5.5 lib/aptible/cli/helpers/app.rb
aptible-cli-0.5.4 lib/aptible/cli/helpers/app.rb
aptible-cli-0.5.2 lib/aptible/cli/helpers/app.rb
aptible-cli-0.5.1 lib/aptible/cli/helpers/app.rb
aptible-cli-0.5.0 lib/aptible/cli/helpers/app.rb
aptible-cli-0.4.4 lib/aptible/cli/helpers/app.rb
aptible-cli-0.4.3 lib/aptible/cli/helpers/app.rb
aptible-cli-0.4.2 lib/aptible/cli/helpers/app.rb
aptible-cli-0.4.1 lib/aptible/cli/helpers/app.rb
aptible-cli-0.4.0 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.7 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.6 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.5 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.4 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.3 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.2 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.1 lib/aptible/cli/helpers/app.rb
aptible-cli-0.3.0 lib/aptible/cli/helpers/app.rb
aptible-cli-0.2.0 lib/aptible/cli/helpers/app.rb