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
ask, 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.
61
62
63
64
65
|
# File 'lib/pagoda/cli/helpers/base.rb', line 61
def initialize(globals, options, args)
@globals = globals
@options = options
@args = args
end
|
Instance Attribute Details
Returns the value of attribute args.
59
60
61
|
# File 'lib/pagoda/cli/helpers/base.rb', line 59
def args
@args
end
|
Returns the value of attribute client.
56
57
58
|
# File 'lib/pagoda/cli/helpers/base.rb', line 56
def client
@client
end
|
Returns the value of attribute globals.
57
58
59
|
# File 'lib/pagoda/cli/helpers/base.rb', line 57
def globals
@globals
end
|
Returns the value of attribute options.
58
59
60
|
# File 'lib/pagoda/cli/helpers/base.rb', line 58
def options
@options
end
|
Class Method Details
.ask_for_credentials ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/pagoda/cli/helpers/base.rb', line 11
def ask_for_credentials
username = ask "Username: "
display "Password: ", false
password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
[username, password] end
|
.ask_for_password ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/pagoda/cli/helpers/base.rb', line 19
def ask_for_password
echo_off
password = ask
puts
echo_on
return password
end
|
.ask_for_password_on_windows ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/pagoda/cli/helpers/base.rb', line 27
def ask_for_password_on_windows
require "Win32API"
char = nil
password = ''
while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
break if char == 10 || char == 13 if char == 127 || char == 8 password.slice!(-1, 1)
else
(password << char.chr) rescue RangeError
end
end
return password
end
|
44
45
46
47
|
# File 'lib/pagoda/cli/helpers/base.rb', line 44
def echo_off
silently(system("stty -echo"))
rescue
end
|
49
50
51
52
|
# File 'lib/pagoda/cli/helpers/base.rb', line 49
def echo_on
silently(system("stty echo"))
rescue
end
|
Instance Method Details
#app(soft_fail = true) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/pagoda/cli/helpers/base.rb', line 89
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 "what is the name of your application? "
else
error "Unable to find the app. please specify using -a or --app="
end
end
end
|
136
137
138
|
# File 'lib/pagoda/cli/helpers/base.rb', line 136
def branch
options[:branch] || find_branch
end
|
140
141
142
|
# File 'lib/pagoda/cli/helpers/base.rb', line 140
def commit
options[:commit] || find_commit
end
|
106
107
108
109
110
111
112
113
|
# File 'lib/pagoda/cli/helpers/base.rb', line 106
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
|
115
116
117
118
119
120
|
# File 'lib/pagoda/cli/helpers/base.rb', line 115
def
remotes = git_remotes
if remotes.length == 1
remotes.values.first
end
end
|
164
165
166
|
# File 'lib/pagoda/cli/helpers/base.rb', line 164
def (remote="pagoda")
git("config remote.#{remote}.url")
end
|
#find_branch ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/pagoda/cli/helpers/base.rb', line 144
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
156
157
158
159
160
161
162
|
# File 'lib/pagoda/cli/helpers/base.rb', line 156
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
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/pagoda/cli/helpers/base.rb', line 122
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
|
152
153
154
|
# File 'lib/pagoda/cli/helpers/base.rb', line 152
def home_dir
File.expand_path("~")
end
|
#locate_app_root(dir = Dir.pwd) ⇒ Object
168
169
170
171
172
173
|
# File 'lib/pagoda/cli/helpers/base.rb', line 168
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/pagoda/cli/helpers/base.rb', line 175
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
|
71
72
73
|
# File 'lib/pagoda/cli/helpers/base.rb', line 71
def password
globals[:password]
end
|
85
86
87
|
# File 'lib/pagoda/cli/helpers/base.rb', line 85
def remote
options[:remote] || "pagoda"
end
|
#shell(cmd) ⇒ Object
81
82
83
|
# File 'lib/pagoda/cli/helpers/base.rb', line 81
def shell(cmd)
FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
end
|
67
68
69
|
# File 'lib/pagoda/cli/helpers/base.rb', line 67
def user
globals[:username]
end
|