Class: Pagoda::Command::Base
Constant Summary
Constants included
from Helpers
Helpers::INDENT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
build_indent, confirm, create_git_remote, display, display_name, error, format_date, git, has_git?, home_directory, remove_app, remove_git_remote, running_on_a_mac?, running_on_windows?
Constructor Details
#initialize(globals, options, args) ⇒ Base
Returns a new instance of Base.
26
27
28
29
30
|
# File 'lib/pagoda/cli/helpers/base.rb', line 26
def initialize(globals, options, args)
@globals = globals
@options = options
@args = args
end
|
Instance Attribute Details
Returns the value of attribute args.
24
25
26
|
# File 'lib/pagoda/cli/helpers/base.rb', line 24
def args
@args
end
|
Returns the value of attribute client.
21
22
23
|
# File 'lib/pagoda/cli/helpers/base.rb', line 21
def client
@client
end
|
Returns the value of attribute globals.
22
23
24
|
# File 'lib/pagoda/cli/helpers/base.rb', line 22
def globals
@globals
end
|
Returns the value of attribute options.
23
24
25
|
# File 'lib/pagoda/cli/helpers/base.rb', line 23
def options
@options
end
|
Class Method Details
.ask_for_credentials ⇒ Object
12
13
14
15
16
17
|
# File 'lib/pagoda/cli/helpers/base.rb', line 12
def ask_for_credentials
username = ask("<%= color('Username: ', :blue) %>")
password = ask("<%= color('Password: ', :blue) %>") { |q| q.echo = '*' }
[username.to_s, password.to_s] end
|
Instance Method Details
#app(soft_fail = true) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/pagoda/cli/helpers/base.rb', line 54
def app(soft_fail=true)
if app = globals[:app] || options[:app]
app
elsif app =
app
elsif app =
app
else
if soft_fail
display "I was unable to find your application name."
ask "<%= color('what is the name of your application? ', :blue) %>"
else
error "Unable to find the app. please specify using -a or --app="
end
end
end
|
101
102
103
|
# File 'lib/pagoda/cli/helpers/base.rb', line 101
def branch
options[:branch] || find_branch
end
|
105
106
107
|
# File 'lib/pagoda/cli/helpers/base.rb', line 105
def commit
options[:commit] || find_commit
end
|
71
72
73
74
75
76
77
78
|
# File 'lib/pagoda/cli/helpers/base.rb', line 71
def
remote = git("config pagoda.id")
if remote =~ /error: More than one value for the key pagoda.id/
git("config --unset-all pagoda.id")
return nil
end
remote == "" ? nil : remote
end
|
80
81
82
83
84
85
|
# File 'lib/pagoda/cli/helpers/base.rb', line 80
def
remotes = git_remotes
if remotes.length == 1
remotes.values.first
end
end
|
129
130
131
|
# File 'lib/pagoda/cli/helpers/base.rb', line 129
def (remote="pagoda")
git("config remote.#{remote}.url")
end
|
#find_branch ⇒ Object
109
110
111
112
113
114
115
|
# File 'lib/pagoda/cli/helpers/base.rb', line 109
def find_branch
if git("name-rev --refs=$(git symbolic-ref HEAD) --name-only HEAD") =~ /Could not get/
error "Cannot find your branch"
else
git("name-rev --refs=$(git symbolic-ref HEAD) --name-only HEAD")
end
end
|
#find_commit ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/pagoda/cli/helpers/base.rb', line 121
def find_commit
if git("rev-parse --verify HEAD") =~ /Could not get/
error "Cannot find your commit"
else
git("rev-parse --verify HEAD")
end
end
|
#git_remotes(base_dir = Dir.pwd) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/pagoda/cli/helpers/base.rb', line 87
def git_remotes(base_dir=Dir.pwd)
remotes = {}
original_dir = Dir.pwd
Dir.chdir(base_dir)
git("remote -v").split("\n").each do |remote|
name, url, method = remote.split(/\s/)
if url =~ /^[email protected]:([\w\d-]+)\.git$/
remotes[name] = $1
end
end
Dir.chdir(original_dir)
remotes
end
|
117
118
119
|
# File 'lib/pagoda/cli/helpers/base.rb', line 117
def home_dir
File.expand_path("~")
end
|
#locate_app_root(dir = Dir.pwd) ⇒ Object
133
134
135
136
137
138
|
# File 'lib/pagoda/cli/helpers/base.rb', line 133
def locate_app_root(dir=Dir.pwd)
return dir if File.exists? "#{dir}/.git/config"
parent = dir.split('/')[0..-2].join('/')
return false if parent.empty?
locate_app_root(parent)
end
|
#loop_transaction(app_name = nil) ⇒ Object
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/pagoda/cli/helpers/base.rb', line 140
def loop_transaction(app_name = nil)
use_app = app_name || app
transaction_id = client.app_info(use_app)[:active_transaction_id]
if transaction_id
log_stream_length = 0
display("",true,0)
while true
start = Time.now
active = client.transaction_info(use_app, transaction_id)
unless active[:log_stream].length == log_stream_length
display( active[:log_stream][log_stream_length..-1].join("\n"),true,0)
log_stream_length = active[:log_stream].length
end
break unless active[:state] == "incomplete"
sleep(Time.now - start) if (Time.now - start) > 0
end
end
display('',true,0)
display( "Complete!",true,0)
display('',true,0)
end
|
36
37
38
|
# File 'lib/pagoda/cli/helpers/base.rb', line 36
def password
globals[:password]
end
|
50
51
52
|
# File 'lib/pagoda/cli/helpers/base.rb', line 50
def remote
options[:remote] || "pagoda"
end
|
#shell(cmd) ⇒ Object
46
47
48
|
# File 'lib/pagoda/cli/helpers/base.rb', line 46
def shell(cmd)
FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
end
|
32
33
34
|
# File 'lib/pagoda/cli/helpers/base.rb', line 32
def user
globals[:username]
end
|