Module: Aptible::CLI::Helpers::App
Defined Under Namespace
Classes: HandleFromGitRemote
Instance Method Summary
collapse
#ensure_default_environment, #ensure_environment, #environment_from_handle, #scoped_environments
Methods included from Token
#current_token_hash, #fetch_token, #save_token, #token_file
Instance Method Details
#app_from_handle(handle, environment) ⇒ Object
39
40
41
42
43
|
# File 'lib/aptible/cli/helpers/app.rb', line 39
def app_from_handle(handle, environment)
environment.apps.find do |a|
a.handle == handle
end
end
|
#default_handle ⇒ Object
53
54
55
|
# File 'lib/aptible/cli/helpers/app.rb', line 53
def default_handle
handle_from_remote(:aptible)
end
|
#ensure_app(options = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/aptible/cli/helpers/app.rb', line 22
def ensure_app(options = {})
remote = options[:remote] || ENV['APTIBLE_REMOTE']
handle = options[:app]
if handle
environment = ensure_environment(options)
else
handles = handle_from_remote(remote) || ensure_default_handle
handle = handles[:app_handle]
env_handle = handles[:environment_handle] || options[:environment]
environment = ensure_environment(environment: env_handle)
end
app = app_from_handle(handle, environment)
return app if app
fail Thor::Error, "Could not find app #{handle}"
end
|
#ensure_default_handle ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/aptible/cli/helpers/app.rb', line 45
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
|
#handle_from_remote(remote_name) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/aptible/cli/helpers/app.rb', line 57
def handle_from_remote(remote_name)
git = Git.open(Dir.pwd)
aptible_remote = git.remote(remote_name).url || ''
HandleFromGitRemote.parse(aptible_remote)
rescue
nil
end
|