Sha256: a3232b4ade58b85d548e1f862e1bf30198f5293ddc924f031c1afc2a6d0ac24d

Contents?: true

Size: 944 Bytes

Versions: 21

Compression:

Stored size: 944 Bytes

Contents

require 'aptible/api'
require 'git'

module Aptible
  module CLI
    module Helpers
      module Account
        include Helpers::Token

        def ensure_account(options = {})
          if (handle = options[:account])
            account = account_from_handle(handle)
            return account if account
            fail "Could not find account #{handle}"
          else
            ensure_default_account
          end
        end

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

        def ensure_default_account
          accounts = Aptible::Api::Account.all(token: fetch_token)
          return accounts.first if accounts.count == 1

          fail Thor::Error, <<-ERR.gsub(/\s+/, ' ').strip
            Multiple accounts available, please specify with --account
          ERR
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
aptible-cli-0.3.5 lib/aptible/cli/helpers/account.rb