vmc 0.4.0.beta.5 → 0.4.0.beta.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/{vmc-ng/LICENSE → LICENSE} +0 -0
  2. data/{vmc-ng/Rakefile → Rakefile} +0 -0
  3. data/bin/vmc +10 -11
  4. data/{vmc-ng/lib → lib}/vmc.rb +0 -0
  5. data/{vmc-ng/lib → lib}/vmc/cli.rb +17 -9
  6. data/{vmc-ng/lib → lib}/vmc/cli/app.rb +31 -31
  7. data/{vmc-ng/lib → lib}/vmc/cli/better_help.rb +0 -0
  8. data/{vmc-ng/lib → lib}/vmc/cli/command.rb +6 -6
  9. data/{vmc-ng/lib → lib}/vmc/cli/dots.rb +63 -8
  10. data/{vmc-ng/lib → lib}/vmc/cli/service.rb +6 -6
  11. data/{vmc-ng/lib → lib}/vmc/cli/user.rb +2 -2
  12. data/{vmc-ng/lib → lib}/vmc/constants.rb +1 -0
  13. data/{vmc-ng/lib → lib}/vmc/detect.rb +0 -0
  14. data/{vmc-ng/lib → lib}/vmc/errors.rb +0 -0
  15. data/{vmc-ng/lib → lib}/vmc/plugin.rb +0 -0
  16. data/lib/vmc/version.rb +3 -0
  17. metadata +33 -281
  18. data/vmc-ng/bin/vmc +0 -14
  19. data/vmc-ng/lib/vmc/version.rb +0 -3
  20. data/vmc/LICENSE +0 -24
  21. data/vmc/README.md +0 -102
  22. data/vmc/Rakefile +0 -101
  23. data/vmc/bin/vmc +0 -6
  24. data/vmc/caldecott_helper/Gemfile +0 -10
  25. data/vmc/caldecott_helper/Gemfile.lock +0 -48
  26. data/vmc/caldecott_helper/server.rb +0 -43
  27. data/vmc/config/clients.yml +0 -17
  28. data/vmc/config/micro/offline.conf +0 -2
  29. data/vmc/config/micro/paths.yml +0 -22
  30. data/vmc/config/micro/refresh_ip.rb +0 -20
  31. data/vmc/lib/cli.rb +0 -47
  32. data/vmc/lib/cli/commands/admin.rb +0 -80
  33. data/vmc/lib/cli/commands/apps.rb +0 -1126
  34. data/vmc/lib/cli/commands/base.rb +0 -227
  35. data/vmc/lib/cli/commands/manifest.rb +0 -56
  36. data/vmc/lib/cli/commands/micro.rb +0 -115
  37. data/vmc/lib/cli/commands/misc.rb +0 -129
  38. data/vmc/lib/cli/commands/services.rb +0 -180
  39. data/vmc/lib/cli/commands/user.rb +0 -65
  40. data/vmc/lib/cli/config.rb +0 -173
  41. data/vmc/lib/cli/console_helper.rb +0 -160
  42. data/vmc/lib/cli/core_ext.rb +0 -122
  43. data/vmc/lib/cli/errors.rb +0 -19
  44. data/vmc/lib/cli/frameworks.rb +0 -265
  45. data/vmc/lib/cli/manifest_helper.rb +0 -302
  46. data/vmc/lib/cli/runner.rb +0 -531
  47. data/vmc/lib/cli/services_helper.rb +0 -84
  48. data/vmc/lib/cli/tunnel_helper.rb +0 -332
  49. data/vmc/lib/cli/usage.rb +0 -115
  50. data/vmc/lib/cli/version.rb +0 -7
  51. data/vmc/lib/cli/zip_util.rb +0 -77
  52. data/vmc/lib/vmc.rb +0 -3
  53. data/vmc/lib/vmc/client.rb +0 -471
  54. data/vmc/lib/vmc/const.rb +0 -22
  55. data/vmc/lib/vmc/micro.rb +0 -56
  56. data/vmc/lib/vmc/micro/switcher/base.rb +0 -97
  57. data/vmc/lib/vmc/micro/switcher/darwin.rb +0 -19
  58. data/vmc/lib/vmc/micro/switcher/dummy.rb +0 -15
  59. data/vmc/lib/vmc/micro/switcher/linux.rb +0 -16
  60. data/vmc/lib/vmc/micro/switcher/windows.rb +0 -31
  61. data/vmc/lib/vmc/micro/vmrun.rb +0 -158
File without changes
File without changes
data/bin/vmc CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
+ # vim: ft=ruby
2
3
 
3
- vmc = File.expand_path("../../vmc", __FILE__)
4
- vmc_ng = File.expand_path("../../vmc-ng", __FILE__)
4
+ require "rubygems"
5
+ require "thor"
5
6
 
6
- bin =
7
- if File.exists?(File.expand_path("~/.vmc/use-ng"))
8
- $LOAD_PATH.unshift "#{vmc_ng}/lib"
9
- "#{vmc_ng}/bin/vmc"
10
- else
11
- "#{vmc}/bin/vmc"
12
- end
7
+ require "vmc"
8
+ require "vmc/plugin"
13
9
 
14
- $0 = bin
15
- load bin
10
+ VMC::Plugin.load_all
11
+
12
+ $exit_status = 0
13
+ VMC::CLI.start(ARGV)
14
+ exit($exit_status)
File without changes
@@ -56,7 +56,7 @@ module VMC
56
56
 
57
57
  runtimes.each do |r|
58
58
  puts ""
59
- puts "#{c(r["name"], :blue)}:"
59
+ puts "#{c(r["name"], :name)}:"
60
60
  puts " version: #{b(r["version"])}"
61
61
  puts " description: #{b(r["description"])}"
62
62
  end
@@ -79,7 +79,7 @@ module VMC
79
79
 
80
80
  services.each do |name, meta|
81
81
  puts ""
82
- puts "#{c(name, :blue)}:"
82
+ puts "#{c(name, :name)}:"
83
83
  puts " versions: #{meta[:versions].join ", "}"
84
84
  puts " description: #{meta[:description]}"
85
85
  puts " type: #{meta[:type]}"
@@ -134,7 +134,7 @@ module VMC
134
134
  end
135
135
 
136
136
  target = sane_target_url(url)
137
- display = c(target.sub(/https?:\/\//, ""), :blue)
137
+ display = c(target.sub(/https?:\/\//, ""), :name)
138
138
  with_progress("Setting target to #{display}") do
139
139
  unless force?
140
140
  # check that the target is valid
@@ -209,7 +209,7 @@ module VMC
209
209
  flag(:no_login, :type => :boolean)
210
210
  def register(email = nil)
211
211
  unless simple_output?
212
- puts "Target: #{c(client_target, :blue)}"
212
+ puts "Target: #{c(client_target, :name)}"
213
213
  puts ""
214
214
  end
215
215
 
@@ -282,7 +282,7 @@ module VMC
282
282
  end
283
283
  end
284
284
 
285
- desc "help [COMMAND]", "usage instructions"
285
+ desc "help [COMMAND]", "Usage instructions"
286
286
  flag :all, :default => false
287
287
  group :start
288
288
  def help(task = nil)
@@ -303,13 +303,21 @@ module VMC
303
303
  end
304
304
  end
305
305
 
306
+ desc "colors", "Show color configuration"
307
+ group :start, :hidden => true
308
+ def colors
309
+ user_colors.each do |n, c|
310
+ puts "#{n}: #{c(c.to_s, n)}"
311
+ end
312
+ end
313
+
306
314
  private
307
315
 
308
316
  def display_service(s)
309
317
  if simple_output?
310
318
  puts s.name
311
319
  else
312
- puts "#{c(s.name, :blue)}: #{s.vendor} v#{s.version}"
320
+ puts "#{c(s.name, :name)}: #{s.vendor} v#{s.version}"
313
321
  end
314
322
  end
315
323
 
@@ -318,8 +326,8 @@ module VMC
318
326
  puts u.email
319
327
  else
320
328
  puts ""
321
- puts "#{c(u.email, :blue)}:"
322
- puts " admin?: #{c(u.admin?, u.admin? ? :green : :red)}"
329
+ puts "#{c(u.email, :name)}:"
330
+ puts " admin?: #{c(u.admin?, u.admin? ? :yes : :no)}"
323
331
  end
324
332
  end
325
333
 
@@ -327,7 +335,7 @@ module VMC
327
335
  if simple_output?
328
336
  puts client.target
329
337
  else
330
- puts "Target: #{c(client.target, :blue)}"
338
+ puts "Target: #{c(client.target, :name)}"
331
339
  end
332
340
  end
333
341
  end
@@ -134,7 +134,7 @@ module VMC
134
134
  service.version = version
135
135
  service.tier = "free"
136
136
 
137
- with_progress("Creating service #{c(service_name, :blue)}") do
137
+ with_progress("Creating service #{c(service_name, :name)}") do
138
138
  service.create!
139
139
  end
140
140
 
@@ -162,7 +162,7 @@ module VMC
162
162
 
163
163
  app.services = bindings
164
164
 
165
- with_progress("Creating #{c(name, :blue)}") do
165
+ with_progress("Creating #{c(name, :name)}") do
166
166
  app.create!
167
167
  end
168
168
 
@@ -194,7 +194,7 @@ module VMC
194
194
 
195
195
  switch_mode(app, input(:debug_mode))
196
196
 
197
- with_progress("Starting #{c(name, :blue)}") do |s|
197
+ with_progress("Starting #{c(name, :name)}") do |s|
198
198
  if app.running?
199
199
  s.skip do
200
200
  err "Already started."
@@ -224,7 +224,7 @@ module VMC
224
224
  fail "No applications given." if names.empty?
225
225
 
226
226
  names.each do |name|
227
- with_progress("Stopping #{c(name, :blue)}") do |s|
227
+ with_progress("Stopping #{c(name, :name)}") do |s|
228
228
  app = client.app(name)
229
229
 
230
230
  unless app.exists?
@@ -265,7 +265,7 @@ module VMC
265
265
  flag(:all, :default => false)
266
266
  def delete(*names)
267
267
  if input(:all)
268
- return unless input(:really, "ALL APPS", :red)
268
+ return unless input(:really, "ALL APPS", :bad)
269
269
 
270
270
  with_progress("Deleting all applications") do
271
271
  client.apps.collect(&:delete!)
@@ -282,13 +282,13 @@ module VMC
282
282
  end
283
283
 
284
284
  names.each do |name|
285
- really = input(:really, name, :blue)
285
+ really = input(:really, name, :name)
286
286
 
287
287
  forget(:really)
288
288
 
289
289
  next unless really
290
290
 
291
- with_progress("Deleting #{c(name, :blue)}") do
291
+ with_progress("Deleting #{c(name, :name)}") do
292
292
  client.app(name).delete!
293
293
  end
294
294
  end
@@ -306,7 +306,7 @@ module VMC
306
306
 
307
307
  names.each do |name|
308
308
  instances =
309
- with_progress("Getting instances for #{c(name, :blue)}") do
309
+ with_progress("Getting instances for #{c(name, :name)}") do
310
310
  client.app(name).instances
311
311
  end
312
312
 
@@ -342,7 +342,7 @@ module VMC
342
342
  memory = input(:memory, app.memory)
343
343
  end
344
344
 
345
- with_progress("Scaling #{c(name, :blue)}") do
345
+ with_progress("Scaling #{c(name, :name)}") do
346
346
  app.total_instances = instances.to_i if instances
347
347
  app.memory = megabytes(memory) if memory
348
348
  app.update!
@@ -376,8 +376,8 @@ module VMC
376
376
  logs =
377
377
  with_progress(
378
378
  "Getting logs for " +
379
- c(name, :blue) + " " +
380
- c("\##{i.index}", :yellow)) do
379
+ c(name, :name) + " " +
380
+ c("\##{i.index}", :instance)) do
381
381
  i.files("logs")
382
382
  end
383
383
 
@@ -441,7 +441,7 @@ module VMC
441
441
  apps.each do |name, status|
442
442
  unless simple_output?
443
443
  puts ""
444
- print "#{c(name, :blue)}: "
444
+ print "#{c(name, :name)}: "
445
445
  end
446
446
 
447
447
  puts status
@@ -460,7 +460,7 @@ module VMC
460
460
  stats = info["stats"]
461
461
  usage = stats["usage"]
462
462
  puts ""
463
- puts "instance #{c("#" + idx, :blue)}:"
463
+ puts "instance #{c("#" + idx, :name)}:"
464
464
  print " cpu: #{percentage(usage["cpu"])} of"
465
465
  puts " #{b(stats["cores"])} cores"
466
466
  puts " memory: #{usage(usage["mem"] * 1024, stats["mem_quota"])}"
@@ -479,7 +479,7 @@ module VMC
479
479
  def map(name, url)
480
480
  simple = url.sub(/^https?:\/\/(.*)\/?/i, '\1')
481
481
 
482
- with_progress("Updating #{c(name, :blue)}") do
482
+ with_progress("Updating #{c(name, :name)}") do
483
483
  app = client.app(name)
484
484
  app.urls << simple
485
485
  app.update!
@@ -494,7 +494,7 @@ module VMC
494
494
  app = client.app(name)
495
495
  fail "Unknown application." unless app.exists?
496
496
 
497
- with_progress("Updating #{c(name, :blue)}") do |s|
497
+ with_progress("Updating #{c(name, :name)}") do |s|
498
498
  unless app.urls.delete(simple)
499
499
  s.fail do
500
500
  err "URL #{url} is not mapped to this application."
@@ -523,7 +523,7 @@ module VMC
523
523
  app = client.app(appname)
524
524
  fail "Unknown application." unless app.exists?
525
525
 
526
- with_progress("Updating #{c(app.name, :blue)}") do
526
+ with_progress("Updating #{c(app.name, :name)}") do
527
527
  app.update!("env" =>
528
528
  app.env.reject { |v|
529
529
  v.start_with?("#{name}=")
@@ -537,7 +537,7 @@ module VMC
537
537
  app = client.app(appname)
538
538
  fail "Unknown application." unless app.exists?
539
539
 
540
- with_progress("Updating #{c(app.name, :blue)}") do
540
+ with_progress("Updating #{c(app.name, :name)}") do
541
541
  app.update!("env" =>
542
542
  app.env.reject { |v|
543
543
  v.start_with?("#{name}=")
@@ -566,7 +566,7 @@ module VMC
566
566
 
567
567
  vars.each do |pair|
568
568
  name, val = pair.split("=", 2)
569
- puts "#{c(name, :blue)}: #{val}"
569
+ puts "#{c(name, :name)}: #{val}"
570
570
  end
571
571
  end
572
572
  end
@@ -577,7 +577,7 @@ module VMC
577
577
  private
578
578
 
579
579
  def upload_app(app, path)
580
- with_progress("Uploading #{c(app.name, :blue)}") do
580
+ with_progress("Uploading #{c(app.name, :name)}") do
581
581
  app.upload(path)
582
582
  end
583
583
  end
@@ -597,7 +597,7 @@ module VMC
597
597
  return true
598
598
  end
599
599
 
600
- with_progress("Switching mode to #{c(mode, :blue)}") do |s|
600
+ with_progress("Switching mode to #{c(mode, :name)}") do |s|
601
601
  runtimes = client.system_runtimes
602
602
  modes = runtimes[app.runtime]["debug_modes"] || []
603
603
  if modes.include?(mode)
@@ -616,7 +616,7 @@ module VMC
616
616
  APP_CHECK_LIMIT = 60
617
617
 
618
618
  def check_application(app)
619
- with_progress("Checking #{c(app.name, :blue)}") do |s|
619
+ with_progress("Checking #{c(app.name, :name)}") do |s|
620
620
  if app.debug_mode == "suspend"
621
621
  s.skip do
622
622
  puts "Application is in suspended debugging mode."
@@ -642,17 +642,17 @@ module VMC
642
642
  def state_color(s)
643
643
  case s
644
644
  when "STARTING"
645
- :blue
645
+ :neutral
646
646
  when "STARTED", "RUNNING"
647
- :green
647
+ :good
648
648
  when "DOWN"
649
- :red
649
+ :bad
650
650
  when "FLAPPING"
651
- :magenta
651
+ :error
652
652
  when "N/A"
653
- :cyan
653
+ :unknown
654
654
  else
655
- :yellow
655
+ :warning
656
656
  end
657
657
  end
658
658
 
@@ -660,7 +660,7 @@ module VMC
660
660
  health = a.health
661
661
 
662
662
  if a.debug_mode == "suspend" && health == "0%"
663
- c("suspended", :yellow)
663
+ c("suspended", :neutral)
664
664
  else
665
665
  c(health.downcase, state_color(health))
666
666
  end
@@ -676,7 +676,7 @@ module VMC
676
676
 
677
677
  status = app_status(a)
678
678
 
679
- print "#{c(a.name, :blue)}: #{status}"
679
+ print "#{c(a.name, :name)}: #{status}"
680
680
 
681
681
  unless a.total_instances == 1
682
682
  print ", #{b(a.total_instances)} instances"
@@ -694,13 +694,13 @@ module VMC
694
694
  end
695
695
 
696
696
  def display_instance(i)
697
- print "instance #{c("\##{i.index}", :blue)}: "
697
+ print "instance #{c("\##{i.index}", :instance)}: "
698
698
  puts "#{b(c(i.state.downcase, state_color(i.state)))} "
699
699
 
700
700
  puts " started: #{c(i.since.strftime("%F %r"), :cyan)}"
701
701
 
702
702
  if d = i.debugger
703
- puts " debugger: port #{c(d["port"], :blue)} at #{c(d["ip"], :blue)}"
703
+ puts " debugger: port #{b(d["port"])} at #{b(d["ip"])}"
704
704
  end
705
705
 
706
706
  if c = i.console
@@ -48,7 +48,7 @@ module VMC
48
48
 
49
49
  def list_choices(choices, options)
50
50
  choices.each_with_index do |o, i|
51
- puts "#{c(i + 1, :green)}: #{o}"
51
+ puts "#{c(i + 1, :number)}: #{o}"
52
52
  end
53
53
  end
54
54
 
@@ -70,7 +70,7 @@ module VMC
70
70
  end
71
71
 
72
72
  print "#{question}"
73
- print c("> ", :blue)
73
+ print c("> ", :prompt)
74
74
 
75
75
  unless value.empty?
76
76
  print "#{c(value, :black) + "\b" * value.size}"
@@ -288,7 +288,7 @@ module VMC
288
288
  if script?
289
289
  $stderr.puts(msg)
290
290
  else
291
- puts c(msg, :red)
291
+ puts c(msg, :error)
292
292
  end
293
293
 
294
294
  $exit_status = 1
@@ -489,11 +489,11 @@ module VMC
489
489
  def percentage(num, low = 50, mid = 70)
490
490
  color =
491
491
  if num <= low
492
- :green
492
+ :good
493
493
  elsif num <= mid
494
- :yellow
494
+ :warning
495
495
  else
496
- :red
496
+ :bad
497
497
  end
498
498
 
499
499
  c(format("%.1f\%", num), color)
@@ -1,3 +1,5 @@
1
+ require "rbconfig"
2
+
1
3
  module VMC
2
4
  module Dots
3
5
  DOT_COUNT = 3
@@ -9,15 +11,15 @@ module VMC
9
11
  end
10
12
 
11
13
  def skip(&callback)
12
- @return.call("SKIPPED", :yellow, callback)
14
+ @return.call("SKIPPED", :warning, callback)
13
15
  end
14
16
 
15
17
  def give_up(&callback)
16
- @return.call("GAVE UP", :red, callback)
18
+ @return.call("GAVE UP", :bad, callback)
17
19
  end
18
20
 
19
21
  def fail(&callback)
20
- @return.call("FAILED", :red, callback)
22
+ @return.call("FAILED", :error, callback)
21
23
  end
22
24
  end
23
25
 
@@ -40,21 +42,23 @@ module VMC
40
42
  res = yield skipper
41
43
  unless simple_output?
42
44
  stop_dots!
43
- puts "... #{c("OK", :green)}"
45
+ puts "... #{c("OK", :good)}"
44
46
  end
45
47
  res
46
48
  rescue
47
49
  unless simple_output?
48
50
  stop_dots!
49
- puts "... #{c("FAILED", :red)}"
51
+ puts "... #{c("FAILED", :error)}"
50
52
  end
51
53
 
52
54
  raise
53
55
  end
54
56
  end
55
57
 
58
+ WINDOWS = !!(RbConfig::CONFIG['host_os'] =~ /mingw|mswin32|cygwin/)
59
+
56
60
  def color?
57
- $stdout.tty?
61
+ !WINDOWS && $stdout.tty?
58
62
  end
59
63
 
60
64
  COLOR_CODES = {
@@ -68,13 +72,64 @@ module VMC
68
72
  :white => 7
69
73
  }
70
74
 
75
+ DEFAULT_COLORS = {
76
+ :name => :blue,
77
+ :neutral => :blue,
78
+ :good => :green,
79
+ :bad => :red,
80
+ :error => :magenta,
81
+ :unknown => :cyan,
82
+ :warning => :yellow,
83
+ :instance => :yellow,
84
+ :number => :green,
85
+ :prompt => :blue,
86
+ :yes => :green,
87
+ :no => :red
88
+ }
89
+
90
+ def user_colors
91
+ return @user_colors if @user_colors
92
+
93
+ colors = File.expand_path VMC::COLORS_FILE
94
+
95
+ if File.exists? colors
96
+ @user_colors = DEFAULT_COLORS.dup
97
+
98
+ YAML.load_file(colors).each do |k, v|
99
+ if k == true
100
+ k = :yes
101
+ elsif k == false
102
+ k = :no
103
+ else
104
+ k = k.to_sym
105
+ end
106
+
107
+ @user_colors[k] = v.to_sym
108
+ end
109
+
110
+ @user_colors
111
+ else
112
+ @user_colors = DEFAULT_COLORS
113
+ end
114
+ end
115
+
71
116
  # colored text
72
117
  #
73
118
  # shouldn't use bright colors, as some color themes abuse
74
119
  # the bright palette (I'm looking at you, Solarized)
75
- def c(str, color)
120
+ def c(str, type)
76
121
  return str unless color?
77
- "\e[3#{COLOR_CODES[color]}m#{str}\e[0m"
122
+
123
+ bright = false
124
+ color = user_colors[type]
125
+ if color =~ /bright-(.+)/
126
+ bright = true
127
+ color = $1.to_sym
128
+ end
129
+
130
+ return str unless color
131
+
132
+ "\e[#{bright ? 9 : 3}#{COLOR_CODES[color]}m#{str}\e[0m"
78
133
  end
79
134
  module_function :c
80
135