vmc 0.4.0.beta.23 → 0.4.0.beta.24

Sign up to get free protection for your applications and to get access to all the features.
data/vmc-ng/lib/vmc.rb CHANGED
@@ -5,3 +5,4 @@ require "vmc/cli/start"
5
5
  require "vmc/cli/app"
6
6
  require "vmc/cli/service"
7
7
  require "vmc/cli/user"
8
+ require "vmc/cli/space"
@@ -10,6 +10,7 @@ require "cfoundry"
10
10
 
11
11
  require "vmc/constants"
12
12
  require "vmc/errors"
13
+ require "vmc/spacing"
13
14
 
14
15
  require "vmc/cli/help"
15
16
  require "vmc/cli/interactive"
@@ -20,6 +21,7 @@ $vmc_asked_auth = false
20
21
  module VMC
21
22
  class CLI < Mothership
22
23
  include VMC::Interactive
24
+ include VMC::Spacing
23
25
  include Mothership::Pretty
24
26
  include Mothership::Progress
25
27
 
@@ -58,7 +60,7 @@ module VMC
58
60
 
59
61
  def default_action
60
62
  if option(:version)
61
- puts "vmc #{VERSION}"
63
+ line "vmc #{VERSION}"
62
64
  else
63
65
  super
64
66
  end
@@ -98,8 +100,8 @@ module VMC
98
100
  if !$vmc_asked_auth && e.error_code == 200
99
101
  $vmc_asked_auth = true
100
102
 
101
- puts ""
102
- puts c("Not authenticated! Try logging in:", :warning)
103
+ line
104
+ line c("Not authenticated! Try logging in:", :warning)
103
105
 
104
106
  invoke :login
105
107
 
@@ -1,3 +1,5 @@
1
+ require "set"
2
+
1
3
  require "vmc/cli"
2
4
  require "vmc/detect"
3
5
 
@@ -71,17 +73,26 @@ module VMC
71
73
  end
72
74
 
73
75
  if apps.empty? and !quiet?
74
- puts ""
75
- puts "No applications."
76
+ line "No applications."
76
77
  return
77
78
  end
78
79
 
79
- apps.each.with_index do |a, num|
80
+ line unless quiet?
81
+
82
+ spaced(apps) do |a|
80
83
  display_app(a) if app_matches(a, input)
81
84
  end
82
85
  end
83
86
 
84
87
 
88
+ desc "Show app information"
89
+ group :apps
90
+ input :app, :argument => :required, :from_given => by_name("app"),
91
+ :desc => "App to show"
92
+ def app(input)
93
+ display_app(input[:app])
94
+ end
95
+
85
96
  desc "Push an application, syncing changes if it exists"
86
97
  group :apps, :manage
87
98
  input(:name, :argument => true, :desc => "Application name") {
@@ -243,14 +254,14 @@ module VMC
243
254
  group :apps, :manage
244
255
  input :apps, :argument => :splat, :singular => :app,
245
256
  :desc => "Applications to start",
246
- :from_given => find_by_name("app")
257
+ :from_given => by_name("app")
247
258
  input :debug_mode, :aliases => "-d",
248
259
  :desc => "Debug mode to start in"
249
260
  def start(input)
250
- apps = input[:apps, client.apps]
261
+ apps = input[:apps]
251
262
  fail "No applications given." if apps.empty?
252
263
 
253
- apps.each do |app|
264
+ spaced(apps) do |app|
254
265
  app = filter(:start_app, app)
255
266
 
256
267
  switch_mode(app, input[:debug_mode])
@@ -271,7 +282,7 @@ module VMC
271
282
  check_application(app)
272
283
 
273
284
  if app.debug_mode && !quiet?
274
- puts ""
285
+ line
275
286
  invoke :instances, :app => app
276
287
  end
277
288
  end
@@ -282,12 +293,12 @@ module VMC
282
293
  group :apps, :manage
283
294
  input :apps, :argument => :splat, :singular => :app,
284
295
  :desc => "Applications to start",
285
- :from_given => find_by_name("app")
296
+ :from_given => by_name("app")
286
297
  def stop(input)
287
- apps = input[:apps, client.apps]
298
+ apps = input[:apps]
288
299
  fail "No applications given." if apps.empty?
289
300
 
290
- apps.each do |app|
301
+ spaced(apps) do |app|
291
302
  with_progress("Stopping #{c(app.name, :name)}") do |s|
292
303
  if app.stopped?
293
304
  s.skip do
@@ -305,14 +316,12 @@ module VMC
305
316
  group :apps, :manage
306
317
  input :apps, :argument => :splat, :singular => :app,
307
318
  :desc => "Applications to start",
308
- :from_given => find_by_name("app")
319
+ :from_given => by_name("app")
309
320
  input :debug_mode, :aliases => "-d",
310
321
  :desc => "Debug mode to start in"
311
322
  def restart(input)
312
- apps = client.apps
313
-
314
- invoke :stop, :apps => input[:apps, apps]
315
- invoke :start, :apps => input[:apps, apps],
323
+ invoke :stop, :apps => input[:apps]
324
+ invoke :start, :apps => input[:apps],
316
325
  :debug_mode => input[:debug_mode]
317
326
  end
318
327
 
@@ -321,7 +330,10 @@ module VMC
321
330
  group :apps, :manage
322
331
  input(:apps, :argument => :splat, :singular => :app,
323
332
  :desc => "Applications to delete",
324
- :from_given => find_by_name("app")) { |apps|
333
+ :from_given => by_name("app")) {
334
+ apps = client.apps
335
+ fail "No applications." if apps.empty?
336
+
325
337
  [ask("Delete which application?", :choices => apps.sort_by(&:name),
326
338
  :display => proc(&:name))]
327
339
  }
@@ -333,32 +345,23 @@ module VMC
333
345
  input :all, :default => false,
334
346
  :desc => "Delete all applications"
335
347
  def delete(input)
348
+ apps = client.apps
349
+
336
350
  if input[:all]
337
351
  return unless input[:really, "ALL APPS", :bad]
338
352
 
339
- apps = client.apps
340
-
341
- orphaned = find_orphaned_services(apps)
342
-
343
- apps.each do |a|
344
- with_progress("Deleting #{c(a.name, :name)}") do
345
- a.delete!
346
- end
347
- end
348
-
349
- delete_orphaned_services(orphaned, input[:orphaned])
350
-
351
- return
353
+ to_delete = apps
354
+ others = []
355
+ else
356
+ to_delete = input[:apps]
357
+ others = apps - to_delete
352
358
  end
353
359
 
354
- apps = client.apps
355
- fail "No applications." if apps.empty?
356
-
357
- to_delete = input[:apps, apps]
360
+ orphaned = find_orphaned_services(to_delete, others)
358
361
 
359
362
  deleted = []
360
- to_delete.each do |app|
361
- really = input[:really, app.name, :name]
363
+ spaced(to_delete) do |app|
364
+ really = input[:all] || input[:really, app.name, :name]
362
365
  next unless really
363
366
 
364
367
  deleted << app
@@ -368,11 +371,9 @@ module VMC
368
371
  end
369
372
  end
370
373
 
371
- unless deleted.empty?
372
- delete_orphaned_services(
373
- find_orphaned_services(deleted, apps - deleted),
374
- input[:orphaned])
375
- end
374
+ delete_orphaned_services(orphaned, input[:orphaned])
375
+
376
+ to_delete
376
377
  end
377
378
 
378
379
 
@@ -380,24 +381,24 @@ module VMC
380
381
  group :apps, :info, :hidden => true
381
382
  input :apps, :argument => :splat, :singular => :app,
382
383
  :desc => "Applications to start",
383
- :from_given => find_by_name("app")
384
+ :from_given => by_name("app")
384
385
  def instances(input)
385
386
  no_v2
386
387
 
387
- apps = input[:apps, client.apps]
388
+ apps = input[:apps]
388
389
  fail "No applications given." if apps.empty?
389
390
 
390
- apps.each do |app|
391
+ spaced(apps) do |app|
391
392
  instances =
392
393
  with_progress("Getting instances for #{c(app.name, :name)}") do
393
394
  app.instances
394
395
  end
395
396
 
396
- instances.each do |i|
397
+ spaced(instances) do |i|
397
398
  if quiet?
398
- puts i.index
399
+ line i.index
399
400
  else
400
- puts ""
401
+ line
401
402
  display_instance(i)
402
403
  end
403
404
  end
@@ -478,7 +479,7 @@ module VMC
478
479
  end
479
480
  end
480
481
 
481
- instances.each do |i|
482
+ spaced(instances) do |i|
482
483
  logs =
483
484
  with_progress(
484
485
  "Getting logs for #{c(app.name, :name)}" +
@@ -486,16 +487,16 @@ module VMC
486
487
  i.files("logs")
487
488
  end
488
489
 
489
- puts "" unless quiet?
490
+ line unless quiet?
490
491
 
491
- logs.each do |log|
492
+ spaced(logs) do |log|
492
493
  body =
493
494
  with_progress("Reading " + b(log.join("/"))) do
494
495
  i.file(*log)
495
496
  end
496
497
 
497
- puts body
498
- puts "" unless body.empty?
498
+ lines body
499
+ line unless body.empty?
499
500
  end
500
501
  end
501
502
  end
@@ -518,7 +519,7 @@ module VMC
518
519
  app.file(*input[:path].split("/"))
519
520
  end
520
521
 
521
- puts "" unless quiet?
522
+ line unless quiet?
522
523
 
523
524
  print file
524
525
  end
@@ -540,9 +541,9 @@ module VMC
540
541
  app.files(*input[:path].split("/"))
541
542
  end
542
543
 
543
- puts "" unless quiet?
544
+ line unless quiet?
544
545
  files.each do |file|
545
- puts file.join("/")
546
+ line file.join("/")
546
547
  end
547
548
  end
548
549
 
@@ -551,9 +552,9 @@ module VMC
551
552
  group :apps, :info, :hidden => true
552
553
  input :apps, :argument => :splat, :singular => :app,
553
554
  :desc => "Applications to start",
554
- :from_given => find_by_name("application")
555
+ :from_given => by_name("app")
555
556
  def health(input)
556
- apps = input[:apps, client.apps]
557
+ apps = input[:apps]
557
558
  fail "No applications given." if apps.empty?
558
559
 
559
560
  health =
@@ -561,12 +562,10 @@ module VMC
561
562
  apps.collect { |a| [a, app_status(a)] }
562
563
  end
563
564
 
564
- health.each do |app, status|
565
- unless quiet?
566
- puts ""
567
- print "#{c(app.name, :name)}: "
568
- end
565
+ line unless quiet?
569
566
 
567
+ spaced(health) do |app, status|
568
+ start_line "#{c(app.name, :name)}: " unless quiet?
570
569
  puts status
571
570
  end
572
571
  end
@@ -587,21 +586,23 @@ module VMC
587
586
  app.stats
588
587
  end
589
588
 
590
- stats.sort_by(&:first).each do |idx, info|
591
- puts ""
589
+ spaced(stats.sort_by(&:first)) do |idx, info|
590
+ line
592
591
 
593
592
  if info[:state] == "DOWN"
594
- puts "Instance #{c("\##{idx}", :instance)} is down."
593
+ line "Instance #{c("\##{idx}", :instance)} is down."
595
594
  next
596
595
  end
597
596
 
598
597
  stats = info[:stats]
599
598
  usage = stats[:usage]
600
- puts "instance #{c("\##{idx}", :instance)}:"
601
- print " cpu: #{percentage(usage[:cpu])} of"
602
- puts " #{b(stats[:cores])} cores"
603
- puts " memory: #{usage(usage[:mem] * 1024, stats[:mem_quota])}"
604
- puts " disk: #{usage(usage[:disk], stats[:disk_quota])}"
599
+ line "instance #{c("\##{idx}", :instance)}:"
600
+
601
+ indented do
602
+ line "cpu: #{percentage(usage[:cpu])} of #{b(stats[:cores])} cores"
603
+ line "memory: #{usage(usage[:mem] * 1024, stats[:mem_quota])}"
604
+ line "disk: #{usage(usage[:disk], stats[:disk_quota])}"
605
+ end
605
606
  end
606
607
  end
607
608
 
@@ -669,10 +670,10 @@ module VMC
669
670
  app.env
670
671
  end
671
672
 
672
- puts "" unless quiet?
673
+ line unless quiet?
673
674
 
674
675
  vars.each do |name, val|
675
- puts "#{c(name, :name)}: #{val}"
676
+ line "#{c(name, :name)}: #{val}"
676
677
  end
677
678
  end
678
679
 
@@ -776,30 +777,30 @@ module VMC
776
777
 
777
778
  def display_app(a)
778
779
  if quiet?
779
- puts a.name
780
+ line a.name
780
781
  return
781
782
  end
782
783
 
783
- puts ""
784
-
785
784
  status = app_status(a)
786
785
 
787
- puts "#{c(a.name, :name)}: #{status}"
786
+ line "#{c(a.name, :name)}: #{status}"
788
787
 
789
- puts " platform: #{b(a.framework.name)} on #{b(a.runtime.name)}"
788
+ indented do
789
+ line "platform: #{b(a.framework.name)} on #{b(a.runtime.name)}"
790
790
 
791
- print " usage: #{b(human_size(a.memory * 1024 * 1024, 0))}"
792
- print " #{c(IS_UTF8 ? "\xc3\x97" : "x", :dim)} #{b(a.total_instances)}"
793
- print " instance#{a.total_instances == 1 ? "" : "s"}"
794
- puts ""
791
+ start_line "usage: #{b(human_size(a.memory * 1024 * 1024, 0))}"
792
+ print " #{c(IS_UTF8 ? "\xc3\x97" : "x", :dim)} #{b(a.total_instances)}"
793
+ print " instance#{a.total_instances == 1 ? "" : "s"}"
795
794
 
796
- unless a.urls.empty?
797
- puts " urls: #{a.urls.collect { |u| b(u) }.join(", ")}"
798
- end
795
+ line
796
+
797
+ unless a.urls.empty?
798
+ line "urls: #{a.urls.collect { |u| b(u) }.join(", ")}"
799
+ end
799
800
 
800
- unless a.services.empty?
801
- print " services: "
802
- puts a.services.collect { |s| b(s.name) }.join(", ")
801
+ unless a.services.empty?
802
+ line "services: #{a.services.collect { |s| b(s.name) }.join(", ")}"
803
+ end
803
804
  end
804
805
  end
805
806
 
@@ -848,8 +849,8 @@ module VMC
848
849
  with_progress("Checking #{c(app.name, :name)}") do |s|
849
850
  if app.debug_mode == "suspend"
850
851
  s.skip do
851
- puts "Application is in suspended debugging mode."
852
- puts "It will wait for you to attach to it before starting."
852
+ line "Application is in suspended debugging mode."
853
+ line "It will wait for you to attach to it before starting."
853
854
  end
854
855
  end
855
856
 
@@ -896,22 +897,24 @@ module VMC
896
897
  end
897
898
 
898
899
  def display_instance(i)
899
- print "instance #{c("\##{i.index}", :instance)}: "
900
+ start_print "instance #{c("\##{i.index}", :instance)}: "
900
901
  puts "#{b(c(i.state.downcase, state_color(i.state)))} "
901
902
 
902
- puts " started: #{c(i.since.strftime("%F %r"), :cyan)}"
903
+ indented do
904
+ line "started: #{c(i.since.strftime("%F %r"), :cyan)}"
903
905
 
904
- if d = i.debugger
905
- puts " debugger: port #{b(d[:port])} at #{b(d[:ip])}"
906
- end
906
+ if d = i.debugger
907
+ line "debugger: port #{b(d[:port])} at #{b(d[:ip])}"
908
+ end
907
909
 
908
- if c = i.console
909
- puts " console: port #{b(c[:port])} at #{b(c[:ip])}"
910
+ if c = i.console
911
+ line "console: port #{b(c[:port])} at #{b(c[:ip])}"
912
+ end
910
913
  end
911
914
  end
912
915
 
913
916
  def find_orphaned_services(apps, others = [])
914
- orphaned = []
917
+ orphaned = Set.new
915
918
 
916
919
  apps.each do |a|
917
920
  a.services.each do |i|
@@ -927,7 +930,7 @@ module VMC
927
930
  def delete_orphaned_services(instances, orphaned)
928
931
  return if instances.empty?
929
932
 
930
- puts "" unless quiet?
933
+ line unless quiet?
931
934
 
932
935
  instances.select { |i|
933
936
  orphaned ||
@@ -7,6 +7,7 @@ Mothership::Help.groups(
7
7
  [:info, "Information"]],
8
8
  [:services, "Services",
9
9
  [:manage, "Management"]],
10
+ [:spaces, "Spaces"],
10
11
  [:admin, "Administration",
11
12
  [:user, "User Management"]])
12
13
 
@@ -30,16 +30,28 @@ module VMC
30
30
  client.service_instances(2)
31
31
  end
32
32
 
33
+ line unless quiet?
34
+
33
35
  if instances.empty? and !quiet?
34
- puts ""
35
- puts "No services."
36
+ line "No services."
36
37
  end
37
38
 
38
- instances.each.with_index do |i, n|
39
- display_instance(i) if instance_matches(i, input)
39
+ spaced(instances) do |i|
40
+ display_service_instance(i) if instance_matches(i, input)
40
41
  end
41
42
  end
42
43
 
44
+
45
+ desc "Show service instance information"
46
+ group :services
47
+ input :instance, :argument => :required,
48
+ :from_given => by_name("service instance", :service_instance),
49
+ :desc => "Service instance to show"
50
+ def service(input)
51
+ display_service_instance(input[:instance])
52
+ end
53
+
54
+
43
55
  services_from_label = proc { |label, services|
44
56
  services.select { |s| s.label == label }
45
57
  }
@@ -89,9 +101,19 @@ module VMC
89
101
  services.reject! { |s| s.version != input[:version] }
90
102
  end
91
103
 
104
+ if plan = input.given(:plan)
105
+ services.reject! { |s|
106
+ if plan.is_a?(String)
107
+ s.service_plans.none? { |p| p.name == plan.upcase }
108
+ else
109
+ s.service_plans.include? plan
110
+ end
111
+ }
112
+ end
113
+
92
114
  until services.size < 2
93
115
  # cast to Array since it might be given as a Service with #invoke
94
- services = Array(input[:service, services])
116
+ services = Array(input[:service, services.sort_by(&:label)])
95
117
  input.forget(:service)
96
118
  end
97
119
 
@@ -130,7 +152,7 @@ module VMC
130
152
  desc "Bind a service instance to an application"
131
153
  group :services, :manage
132
154
  input(:instance, :argument => true,
133
- :from_given => by_name("instance", :service_instance),
155
+ :from_given => by_name("service instance", :service_instance),
134
156
  :desc => "Service to bind") { |app|
135
157
  instances = client.service_instances
136
158
  fail "No service instances." if instances.empty?
@@ -165,20 +187,20 @@ module VMC
165
187
  desc "Unbind a service from an application"
166
188
  group :services, :manage
167
189
  input(:instance, :argument => true,
168
- :from_given => find_by_name("instance"),
169
- :desc => "Service to bind") { |instances|
170
- ask "Which service instance?", :choices => instances,
190
+ :from_given => find_by_name("service instance"),
191
+ :desc => "Service to bind") { |app|
192
+ ask "Which service instance?", :choices => app.services,
171
193
  :display => proc(&:name)
172
194
  }
173
195
  input(:app, :argument => true,
174
196
  :from_given => find_by_name("app"),
175
- :desc => "Application to bind to") { |apps|
176
- ask "Which application?", :choices => apps,
197
+ :desc => "Application to bind to") {
198
+ ask "Which application?", :choices => client.apps(2),
177
199
  :display => proc(&:name)
178
200
  }
179
201
  def unbind_service(input)
180
- app = input[:app, client.apps(2)]
181
- instance = input[:instance, app.services]
202
+ app = input[:app]
203
+ instance = input[:instance, app]
182
204
 
183
205
  with_progress(
184
206
  "Unbinding #{c(instance.name, :name)} from #{c(app.name, :name)}") do
@@ -190,8 +212,11 @@ module VMC
190
212
  desc "Delete a service"
191
213
  group :services, :manage
192
214
  input(:instance, :argument => true,
193
- :from_given => find_by_name("instance"),
194
- :desc => "Service to bind") { |instances|
215
+ :from_given => by_name("service instance", :service_instance),
216
+ :desc => "Service to bind") {
217
+ instances = client.service_instances
218
+ fail "No services." if instances.empty?
219
+
195
220
  ask "Which service instance?", :choices => instances,
196
221
  :display => proc(&:name)
197
222
  }
@@ -210,10 +235,7 @@ module VMC
210
235
  return
211
236
  end
212
237
 
213
- instances = client.service_instances
214
- fail "No services." if instances.empty?
215
-
216
- instance = input[:instance, instances]
238
+ instance = input[:instance]
217
239
 
218
240
  return unless input[:really, instance.name, :name]
219
241
 
@@ -259,18 +281,23 @@ module VMC
259
281
  true
260
282
  end
261
283
 
262
- def display_instance(i)
284
+ def display_service_instance(i)
263
285
  if quiet?
264
- puts i.name
286
+ line i.name
265
287
  else
266
288
  plan = i.service_plan
267
289
  service = plan.service
268
290
 
269
- puts ""
270
- puts "#{c(i.name, :name)}: #{service.label} #{service.version}"
271
- puts " description: #{service.description}"
272
- puts " plan: #{c(plan.name, :name)}"
273
- puts " description: #{plan.description}"
291
+ line "#{c(i.name, :name)}: #{service.label} #{service.version}"
292
+
293
+ indented do
294
+ line "description: #{service.description}"
295
+ line "plan: #{c(plan.name, :name)}"
296
+
297
+ indented do
298
+ line "description: #{plan.description}"
299
+ end
300
+ end
274
301
  end
275
302
  end
276
303
 
@@ -0,0 +1,67 @@
1
+ require "vmc/cli"
2
+
3
+ module VMC
4
+ class Space < CLI
5
+ def precondition
6
+ super
7
+ fail "This command is v2-only." unless v2?
8
+ end
9
+
10
+ def self.by_name(what, obj = what)
11
+ proc { |name, *_|
12
+ client.send(:"#{obj}_by_name", name) ||
13
+ fail("Unknown #{what} '#{name}'")
14
+ }
15
+ end
16
+
17
+ desc "Show space information"
18
+ group :spaces
19
+ input(:space, :argument => :optional, :from_given => by_name("space"),
20
+ :desc => "Space to show") {
21
+ client.current_space
22
+ }
23
+ input :full, :type => :boolean,
24
+ :desc => "Show full information for apps, service instances, etc."
25
+ def space(input)
26
+ space = input[:space]
27
+
28
+ line "name: #{c(space.name, :name)}"
29
+ line "organization: #{c(space.organization.name, :name)}"
30
+
31
+ if input[:full]
32
+ line
33
+ line "apps:"
34
+
35
+ spaced(space.apps(2)) do |a|
36
+ indented do
37
+ invoke :app, :app => a
38
+ end
39
+ end
40
+ else
41
+ line "apps: #{name_list(space.apps)}"
42
+ end
43
+
44
+ if input[:full]
45
+ line
46
+ line "services:"
47
+ spaced(space.service_instances(2)) do |i|
48
+ indented do
49
+ invoke :service, :instance => i
50
+ end
51
+ end
52
+ else
53
+ line "services: #{name_list(space.service_instances)}"
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def name_list(xs)
60
+ if xs.empty?
61
+ c("none", :dim)
62
+ else
63
+ xs.collect { |x| c(x.name, :name) }.join(", ")
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,5 @@
1
+ require "base64"
2
+
1
3
  require "vmc/cli"
2
4
 
3
5
  module VMC
@@ -26,10 +28,10 @@ module VMC
26
28
  group :start
27
29
  input :runtimes, :type => :boolean,
28
30
  :desc => "List supported runtimes"
29
- input :services, :type => :boolean,
30
- :desc => "List supported services"
31
31
  input :frameworks, :type => :boolean,
32
32
  :desc => "List supported frameworks"
33
+ input :services, :type => :boolean,
34
+ :desc => "List supported services"
33
35
  input(:all, :type => :boolean, :alias => "-a",
34
36
  :desc => "Show all information")
35
37
  def info(input)
@@ -42,13 +44,6 @@ module VMC
42
44
  end
43
45
  end
44
46
 
45
- if all || input[:services]
46
- services =
47
- with_progress("Getting services") do
48
- client.services
49
- end
50
- end
51
-
52
47
  if all || input[:frameworks]
53
48
  frameworks =
54
49
  with_progress("Getting frameworks") do
@@ -56,63 +51,82 @@ module VMC
56
51
  end
57
52
  end
58
53
 
54
+ if all || input[:services]
55
+ services =
56
+ with_progress("Getting services") do
57
+ client.services
58
+ end
59
+ end
60
+
59
61
  info = client.info
60
62
 
61
63
  showing_any = runtimes || services || frameworks
62
64
 
63
65
  unless !all && showing_any
64
- puts "" if showing_any
65
- puts info[:description]
66
- puts ""
67
- puts "target: #{b(client.target)}"
68
- puts " version: #{info[:version]}"
69
- puts " support: #{info[:support]}"
66
+ line if showing_any
67
+ line info[:description]
68
+ line
69
+ line "target: #{b(client.target)}"
70
+
71
+ indented do
72
+ line "version: #{info[:version]}"
73
+ line "support: #{info[:support]}"
74
+ end
70
75
 
71
76
  if user = client.current_user
72
- puts ""
73
- puts "user: #{b(user.email || user.guid)}"
77
+ line
78
+ line "user: #{b(user.email || token_data[:email] || user.guid)}"
74
79
  end
75
80
  end
76
81
 
77
82
  if runtimes
78
83
  unless quiet?
79
- puts ""
80
- puts "runtimes:"
84
+ line
85
+ line "runtimes:"
81
86
  end
82
87
 
83
- puts " #{c("none", :dim)}" if runtimes.empty? && !quiet?
84
-
85
- runtimes.each.with_index do |r, i|
86
- display_runtime(r)
87
- puts "" unless quiet? || i + 1 == runtimes.size
88
+ indented do
89
+ if runtimes.empty? && !quiet?
90
+ line "#{c("none", :dim)}"
91
+ else
92
+ spaced(runtimes) do |r|
93
+ display_runtime(r)
94
+ end
95
+ end
88
96
  end
89
97
  end
90
98
 
91
- if services
99
+ if frameworks
92
100
  unless quiet?
93
- puts ""
94
- puts "services:"
101
+ line
102
+ line "frameworks:"
95
103
  end
96
104
 
97
- puts " #{c("none", :dim)}" if services.empty? && !quiet?
98
-
99
- services.each.with_index do |s, i|
100
- display_service(s)
101
- puts "" unless quiet? || i + 1 == services.size
105
+ indented do
106
+ if frameworks.empty? && !quiet?
107
+ line "#{c("none", :dim)}"
108
+ else
109
+ spaced(frameworks) do |f|
110
+ display_framework(f)
111
+ end
112
+ end
102
113
  end
103
114
  end
104
115
 
105
- if frameworks
116
+ if services
106
117
  unless quiet?
107
- puts ""
108
- puts "frameworks:"
118
+ line
119
+ line "services:"
109
120
  end
110
121
 
111
- puts " #{c("none", :dim)}" if frameworks.empty? && !quiet?
112
-
113
- frameworks.each.with_index do |f, i|
114
- display_framework(f)
115
- puts "" unless quiet? || i + 1 == frameworks.size
122
+ indented do
123
+ if services.empty? && !quiet?
124
+ line "#{c("none", :dim)}"
125
+ else
126
+ spaced(services) do |s|
127
+ display_service(s)
128
+ end
129
+ end
116
130
  end
117
131
  end
118
132
  end
@@ -137,6 +151,7 @@ module VMC
137
151
  if !input[:interactive] && !input.given?(:url) &&
138
152
  !input.given?(:organization) && !input.given?(:space)
139
153
  display_target
154
+ display_org_and_space unless quiet?
140
155
  return
141
156
  end
142
157
 
@@ -157,6 +172,9 @@ module VMC
157
172
  select_org_and_space(input, info)
158
173
 
159
174
  save_target_info(info)
175
+ elsif !quiet?
176
+ line
177
+ display_org_and_space
160
178
  end
161
179
  end
162
180
 
@@ -165,7 +183,7 @@ module VMC
165
183
  group :start, :hidden => true
166
184
  def targets(input)
167
185
  targets_info.each do |target, _|
168
- puts target
186
+ line target
169
187
  # TODO: print org/space
170
188
  end
171
189
  end
@@ -189,7 +207,7 @@ module VMC
189
207
  ask("Space", :choices => spaces, :display => proc(&:name))
190
208
  }
191
209
  def login(input)
192
- display_target unless quiet?
210
+ show_context
193
211
 
194
212
  credentials =
195
213
  { :username => input[:username],
@@ -232,7 +250,7 @@ module VMC
232
250
  invalidate_client
233
251
 
234
252
  if v2?
235
- puts "" if input[:interactive]
253
+ line if input[:interactive]
236
254
  select_org_and_space(input, info)
237
255
  save_target_info(info)
238
256
  end
@@ -264,7 +282,7 @@ module VMC
264
282
  input :login, :type => :boolean, :default => true,
265
283
  :desc => "Automatically log in?"
266
284
  def register(input)
267
- display_target unless quiet?
285
+ show_context
268
286
 
269
287
  email = input[:email]
270
288
  password = input[:password]
@@ -287,7 +305,7 @@ module VMC
287
305
  group :start, :hidden => true
288
306
  def colors(input)
289
307
  user_colors.each do |n, c|
290
- puts "#{n}: #{c(c.to_s, n)}"
308
+ line "#{n}: #{c(c.to_s, n)}"
291
309
  end
292
310
  end
293
311
 
@@ -310,30 +328,33 @@ module VMC
310
328
  end
311
329
  end
312
330
 
313
- def display_target
314
- return if displayed_target?
331
+ def show_context
332
+ return if quiet? || displayed_target?
333
+
334
+ display_target
315
335
 
336
+ line
337
+
338
+ @@displayed_target = true
339
+ end
340
+
341
+ def display_target
316
342
  if quiet?
317
343
  puts client.target
318
344
  else
319
- puts "target: #{c(client.target, :name)}"
320
- display_org_and_space
345
+ line "target: #{c(client.target, :name)}"
321
346
  end
322
-
323
- puts ""
324
-
325
- @@displayed_target = true
326
347
  end
327
348
 
328
349
  def display_org_and_space
329
350
  return unless v2?
330
351
 
331
352
  if org = client.current_organization
332
- puts "organization: #{c(org.name, :name)}"
353
+ line "organization: #{c(org.name, :name)}"
333
354
  end
334
355
 
335
356
  if space = client.current_space
336
- puts "space: #{c(space.name, :name)}"
357
+ line "space: #{c(space.name, :name)}"
337
358
  end
338
359
  rescue CFoundry::APIError
339
360
  end
@@ -342,14 +363,16 @@ module VMC
342
363
  if quiet?
343
364
  puts r.name
344
365
  else
345
- puts " #{c(r.name, :name)}:"
366
+ line "#{c(r.name, :name)}:"
346
367
 
347
- puts " description: #{b(r.description)}" if r.description
368
+ indented do
369
+ line "description: #{b(r.description)}" if r.description
348
370
 
349
- # TODO: probably won't have this in final version
350
- apps = r.apps.collect { |a| c(a.name, :name) }
351
- app_list = apps.empty? ? c("none", :dim) : apps.join(", ")
352
- puts " apps: #{app_list}"
371
+ # TODO: probably won't have this in final version
372
+ apps = r.apps.collect { |a| c(a.name, :name) }
373
+ app_list = apps.empty? ? c("none", :dim) : apps.join(", ")
374
+ line "apps: #{app_list}"
375
+ end
353
376
  end
354
377
  end
355
378
 
@@ -357,10 +380,13 @@ module VMC
357
380
  if quiet?
358
381
  puts s.label
359
382
  else
360
- puts " #{c(s.label, :name)}:"
361
- puts " description: #{s.description}"
362
- puts " version: #{s.version}"
363
- puts " provider: #{s.provider}"
383
+ line "#{c(s.label, :name)}:"
384
+
385
+ indented do
386
+ line "description: #{s.description}"
387
+ line "version: #{s.version}"
388
+ line "provider: #{s.provider}"
389
+ end
364
390
  end
365
391
  end
366
392
 
@@ -368,12 +394,15 @@ module VMC
368
394
  if quiet?
369
395
  puts f.name
370
396
  else
371
- puts " #{c(f.name, :name)}:"
372
- puts " description: #{b(f.description)}" if f.description
397
+ line "#{c(f.name, :name)}:"
373
398
 
374
- # TODO: probably won't show this in final version; just for show
375
- apps = f.apps.collect { |a| c(a.name, :name) }
376
- puts " apps: #{apps.empty? ? c("none", :dim) : apps.join(", ")}"
399
+ indented do
400
+ line "description: #{b(f.description)}" if f.description
401
+
402
+ # TODO: probably won't show this in final version; just for show
403
+ apps = f.apps.collect { |a| c(a.name, :name) }
404
+ line "apps: #{apps.empty? ? c("none", :dim) : apps.join(", ")}"
405
+ end
377
406
  end
378
407
  end
379
408
 
@@ -423,7 +452,7 @@ module VMC
423
452
  if !input[:interactive] && spaces.size == 1 && !input.given?(:space)
424
453
  space = spaces.first
425
454
  else
426
- puts "" if input[:interactive] && changed_org
455
+ line if input[:interactive] && changed_org
427
456
  space = input[:space, spaces.sort_by(&:name)]
428
457
  end
429
458
 
@@ -432,5 +461,21 @@ module VMC
432
461
  end
433
462
  end
434
463
  end
464
+
465
+ # grab the metadata from a token that looks like:
466
+ #
467
+ # bearer (base64 ...)
468
+ def token_data
469
+ return @token_data if @token_data
470
+
471
+ tok = Base64.decode64(client.base.token.sub(/^bearer\s+/, ""))
472
+ tok.sub!(/\{.+?\}/, "") # clear algo
473
+ @token_data = JSON.parse(tok[/\{.+?\}/], :symbolize_names => true)
474
+
475
+ # normally i don't catch'em all, but can't expect all tokens to be the
476
+ # proper format, so just silently fail as this is not critical
477
+ rescue
478
+ {}
479
+ end
435
480
  end
436
481
  end
@@ -10,7 +10,7 @@ module VMC
10
10
  client.users
11
11
  end
12
12
 
13
- users.each do |u|
13
+ spaced(users) do |u|
14
14
  display_user(u)
15
15
  end
16
16
  end
@@ -91,9 +91,11 @@ module VMC
91
91
  if quiet?
92
92
  puts u.email
93
93
  else
94
- puts ""
95
- puts "#{c(u.email, :name)}:"
96
- puts " admin?: #{c(u.admin?, u.admin? ? :yes : :no)}"
94
+ line "#{c(u.email, :name)}:"
95
+
96
+ indented do
97
+ line "admin?: #{c(u.admin?, u.admin? ? :yes : :no)}"
98
+ end
97
99
  end
98
100
  end
99
101
  end
@@ -0,0 +1,45 @@
1
+ module VMC
2
+ module Spacing
3
+ @@indentation = 0
4
+
5
+ def indented
6
+ @@indentation += 1
7
+ yield
8
+ ensure
9
+ @@indentation -= 1
10
+ end
11
+
12
+ def line(msg = "")
13
+ return puts "" if msg.empty?
14
+
15
+ start_line(msg)
16
+ puts ""
17
+ end
18
+
19
+ def start_line(msg)
20
+ print " " * @@indentation
21
+ print msg
22
+ end
23
+
24
+ def lines(blob)
25
+ blob.each_line do |line|
26
+ start_line(line)
27
+ end
28
+
29
+ line
30
+ end
31
+
32
+ def quiet?
33
+ false
34
+ end
35
+
36
+ def spaced(vals)
37
+ num = 0
38
+ vals.each do |val|
39
+ line unless quiet? || num == 0
40
+ yield val
41
+ num += 1
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.4.0.beta.23"
2
+ VERSION = "0.4.0.beta.24"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196429
4
+ hash: 62196435
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 23
12
- version: 0.4.0.beta.23
11
+ - 24
12
+ version: 0.4.0.beta.24
13
13
  platform: ruby
14
14
  authors:
15
15
  - VMware
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-07-23 00:00:00 Z
20
+ date: 2012-07-24 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -249,12 +249,12 @@ dependencies:
249
249
  requirements:
250
250
  - - ~>
251
251
  - !ruby/object:Gem::Version
252
- hash: 7
252
+ hash: 5
253
253
  segments:
254
254
  - 0
255
255
  - 3
256
- - 10
257
- version: 0.3.10
256
+ - 11
257
+ version: 0.3.11
258
258
  type: :runtime
259
259
  version_requirements: *id014
260
260
  - !ruby/object:Gem::Dependency
@@ -281,12 +281,12 @@ dependencies:
281
281
  requirements:
282
282
  - - ~>
283
283
  - !ruby/object:Gem::Version
284
- hash: 15
284
+ hash: 13
285
285
  segments:
286
286
  - 0
287
287
  - 4
288
- - 0
289
- version: 0.4.0
288
+ - 1
289
+ version: 0.4.1
290
290
  type: :runtime
291
291
  version_requirements: *id016
292
292
  - !ruby/object:Gem::Dependency
@@ -374,6 +374,7 @@ files:
374
374
  - vmc-ng/lib/vmc/cli/help.rb
375
375
  - vmc-ng/lib/vmc/cli/interactive.rb
376
376
  - vmc-ng/lib/vmc/cli/service.rb
377
+ - vmc-ng/lib/vmc/cli/space.rb
377
378
  - vmc-ng/lib/vmc/cli/start.rb
378
379
  - vmc-ng/lib/vmc/cli/user.rb
379
380
  - vmc-ng/lib/vmc/cli.rb
@@ -381,6 +382,7 @@ files:
381
382
  - vmc-ng/lib/vmc/detect.rb
382
383
  - vmc-ng/lib/vmc/errors.rb
383
384
  - vmc-ng/lib/vmc/plugin.rb
385
+ - vmc-ng/lib/vmc/spacing.rb
384
386
  - vmc-ng/lib/vmc/version.rb
385
387
  - vmc-ng/lib/vmc.rb
386
388
  - vmc-ng/spec/app/apps_spec.rb