Module: Aptible::CLI::Helpers::Account
- Includes:
- Token
- Defined in:
- lib/aptible/cli/helpers/account.rb
Instance Method Summary
collapse
Methods included from Token
#current_token_hash, #fetch_token, #save_token, #token_file
Instance Method Details
#account_from_handle(handle) ⇒ Object
20
21
22
23
24
|
# File 'lib/aptible/cli/helpers/account.rb', line 20
def account_from_handle(handle)
Aptible::Api::Account.all(token: fetch_token).find do |a|
a.handle == handle
end
end
|
#ensure_account(options = {}) ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/aptible/cli/helpers/account.rb', line 10
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
|
#ensure_default_account ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/aptible/cli/helpers/account.rb', line 26
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
|