ubalo 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/ubalo +41 -57
  2. data/lib/ubalo.rb +24 -35
  3. metadata +8 -8
data/bin/ubalo CHANGED
@@ -44,7 +44,7 @@ def ubalo
44
44
  end
45
45
 
46
46
  program_desc 'Command-line access to ubalo.com.'
47
- version "0.0.4"
47
+ version "0.0.6"
48
48
 
49
49
  desc "Change the connect url"
50
50
  flag 'connect-url'
@@ -56,39 +56,28 @@ command :whoami do |c|
56
56
  end
57
57
  end
58
58
 
59
- desc 'Display pods'
60
- command :pods do |c|
61
- c.desc 'show all pods you can snap (default)'
62
- c.switch :all
63
-
64
- c.desc 'show only your pods'
65
- c.switch :mine
66
-
67
- c.desc 'show only the pods you can edit and snap'
68
- c.switch :editable
69
-
59
+ desc 'Display a list of available pods'
60
+ command :list do |c|
70
61
  c.action do |global_options,options,args|
71
- unless options.all or options.edit_only
72
- # Default to showing just your pods.
73
- options.mine = true
74
- end
75
-
76
- your_pods, editable_pods, snappable_pods = ubalo.pods
62
+ response = ubalo.pods
77
63
 
78
- # Always show your pods.
79
- your_pods.each do |pod|
80
- puts Ubalo.format_pod(pod)
81
- end
82
-
83
- if options.all or options.edit_only
84
- editable_pods.each do |pod|
85
- puts Ubalo.format_pod(pod)
64
+ puts "your pods:"
65
+ your_pods = response['your_pods']
66
+ if your_pods.empty?
67
+ puts " (none)"
68
+ else
69
+ response['your_pods'].each do |pod|
70
+ puts Ubalo.format_pod(pod, false)
86
71
  end
87
72
  end
88
73
 
89
- if options.all
90
- snappable_pods.each do |pod|
91
- puts Ubalo.format_pod(pod)
74
+ puts "other pods:"
75
+ other_pods = response['other_pods']
76
+ if other_pods.empty?
77
+ puts " (none)"
78
+ else
79
+ other_pods.each do |pod|
80
+ puts Ubalo.format_pod(pod, true)
92
81
  end
93
82
  end
94
83
  end
@@ -230,15 +219,7 @@ end
230
219
 
231
220
  desc 'Snap a pod'
232
221
  arg_name '<pod name>'
233
- command :snap do |c|
234
- c.desc 'detach, leaving task running in the background; return an id'
235
- c.switch [:detach, :d]
236
-
237
- c.desc 'explicitly show the complete result'
238
- c.switch [:verbose, :v]
239
-
240
- c.desc 'outputs as json to stdout; stdout > stderr'
241
- c.switch [:json, :j]
222
+ command :run do |c|
242
223
 
243
224
  c.action do |global_options,options,args|
244
225
  pod_name = args.shift
@@ -246,15 +227,12 @@ command :snap do |c|
246
227
  raise "please specify a pod"
247
228
  end
248
229
 
249
- h = ubalo.submit_task(pod_name, args.join(" "))
250
- task_id = h['id']
230
+ $stderr.print "Running #{pod_name}..."
231
+ response = ubalo.submit_task(pod_name, args.join(" "))
232
+ task_id = response['id']
251
233
 
252
- if options.detach
253
- puts task_id
254
- else
255
- result = ubalo.check_task(task_id, true)
256
- ubalo.show_result(result, options.verbose, options.json)
257
- end
234
+ result = ubalo.check_task(task_id, true)
235
+ ubalo.show_result(result)
258
236
  end
259
237
  end
260
238
 
@@ -281,38 +259,44 @@ command :check do |c|
281
259
  end
282
260
  end
283
261
 
284
- desc 'Retrieve an API token'
285
- command :authorize do |c|
262
+ desc 'Sign into Ubalo'
263
+ command :signin do |c|
286
264
  c.action do |global_options,options,args|
287
265
  puts "Please enter your Ubalo username/email and password to unlock command-line access."
288
266
  login = hl.ask(" login: "){|q| q.echo = true}
289
267
  password = hl.ask(" password: "){|q| q.echo = false}
290
268
 
291
269
  ubalo.token = ubalo.get_api_token(login, password)
292
- Ubalo.write_config('token' => ubalo.token)
270
+ Ubalo.write_config("connect-url" => ubalo.base_url, ubalo.base_url => {'token' => ubalo.token})
293
271
  puts "Access details saved to ~/.ubalorc."
294
272
  puts ubalo.whoami
295
273
  end
296
274
  end
297
275
 
298
- desc 'Clear any stored API tokens'
299
- command :deauthorize do |c|
276
+ desc 'Sign out of Ubalo'
277
+ command :signout do |c|
300
278
  c.action do |global_options,options,args|
301
- Ubalo.write_config('token' => nil)
279
+ Ubalo.write_config(ubalo.base_url => nil)
302
280
  puts "Access details deleted."
303
281
  end
304
282
  end
305
283
 
306
284
  pre do |global,command,options,args|
307
285
  config = Ubalo.config
308
- token = config['token']
286
+ connect_url = global['connect-url'] || config['connect-url']
287
+
288
+ # When signing in, don't use the token:
289
+ unless command && command.name == :signin
290
+ if host_config = config[connect_url]
291
+ token = host_config['token']
292
+ end
293
+ end
309
294
 
310
- unless token or (command && command.name == :authorize)
311
- raise "No credentials found. Please run 'ubalo authorize'."
295
+ unless token or (command && command.name == :signin)
296
+ raise "No credentials found. Please run 'ubalo signin'."
312
297
  end
313
298
 
314
- connect_url = global['connect-url'] || config['connect-url']
315
- @ubalo ||= Ubalo.authorize(token, connect_url)
299
+ @ubalo ||= Ubalo.signin(token, connect_url)
316
300
 
317
301
  true
318
302
  end
data/lib/ubalo.rb CHANGED
@@ -50,15 +50,20 @@ class Ubalo
50
50
  "#{task['id'].to_s[0,6]} #{task['state'].lfit(8)} #{task['pod_name'].lfit(25)} #{task['arg'].to_s.lfit(40)}"
51
51
  end
52
52
 
53
- def format_pod pod
54
- "#{pod['environ'].lfit(18)} #{pod['code_lines'].to_s.rjust 3} lines #{pod['user'].rfit(10)} / #{pod['name']}"
53
+ def format_pod pod, with_username
54
+ if with_username
55
+ name = "#{pod['user']}/#{pod['name']}"
56
+ else
57
+ name = pod['name']
58
+ end
59
+ " #{name} - #{pod['environ']}"
55
60
  end
56
61
  end
57
62
 
58
63
  attr_reader :base_url
59
64
  attr_accessor :token
60
65
 
61
- def self.authorize token, base_url=nil
66
+ def self.signin token, base_url=nil
62
67
  new(token, base_url)
63
68
  end
64
69
 
@@ -95,7 +100,6 @@ class Ubalo
95
100
  end
96
101
 
97
102
  def submit_task(pod_name, arg)
98
- $stderr.puts "Snapping #{pod_name}"
99
103
  parse(post(:submit_task, {:pod_name => pod_name, :arg => arg}))
100
104
  end
101
105
 
@@ -104,7 +108,7 @@ class Ubalo
104
108
  60.times do
105
109
  h = check_task_once(id)
106
110
  if %w{complete failed}.include?(h['state'])
107
- $stderr.puts "done"
111
+ $stderr.puts " done."
108
112
  return h
109
113
  end
110
114
  $stderr.print '.'
@@ -140,8 +144,7 @@ class Ubalo
140
144
  end
141
145
 
142
146
  def pods
143
- h = parse(get(:pods))
144
- [h['your_pods'], h['editable_pods'], h['snappable_pods']]
147
+ parse(get(:pods))
145
148
  end
146
149
 
147
150
  def ssh(pod_name)
@@ -170,36 +173,22 @@ class Ubalo
170
173
  if json
171
174
  puts outputs
172
175
  else
173
- if verbose
174
- puts " id: #{result['id']}"
175
- puts " name: #{result['pod_name']}"
176
- puts " state: #{result['state']}"
177
- puts "status: #{result['status']}"
178
- if result['stdout']
179
- puts "stdout:"
180
- puts result['stdout'].indent
181
- end
182
- if result['stderr']
183
- puts "stderr:"
184
- puts result['stderr'].indent
185
- end
186
- else
187
- if result['stdout']
188
- print result['stdout']
189
- end
190
- if result['stderr']
191
- $stderr.print result['stderr']
192
- end
193
-
194
- exit_code = Integer(result['status'] || 0)
195
- unless exit_code.zero?
196
- raise UbaloExit, exit_code
197
- end
176
+ puts " id: #{result['id']}"
177
+ puts " name: #{result['pod_name']}"
178
+ puts " arg: #{result['arg']}"
179
+ puts " state: #{result['state']}"
180
+ puts "status: #{result['status']}" if result['status']
181
+ if result['stdout']
182
+ puts "stdout:"
183
+ puts result['stdout'].indent
184
+ end
185
+ if result['stderr']
186
+ puts "stderr:"
187
+ puts result['stderr'].indent
198
188
  end
199
-
200
189
  if outputs
201
- $stderr.puts "outputs:"
202
- $stderr.puts outputs.indent
190
+ puts "outputs:"
191
+ puts outputs.indent
203
192
  end
204
193
  end
205
194
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubalo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-29 00:00:00.000000000Z
12
+ date: 2011-12-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &2157151880 !ruby/object:Gem::Requirement
16
+ requirement: &2153089760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157151880
24
+ version_requirements: *2153089760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &2157151440 !ruby/object:Gem::Requirement
27
+ requirement: &2153089320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157151440
35
+ version_requirements: *2153089320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rest-client
38
- requirement: &2157150940 !ruby/object:Gem::Requirement
38
+ requirement: &2153088800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.6.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2157150940
46
+ version_requirements: *2153088800
47
47
  description: CLI and API client for Ubalo
48
48
  email: dev@ubalo.com
49
49
  executables: