af 0.3.22 → 0.5.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +14 -6
  2. data/LICENSE +1277 -24
  3. data/Rakefile +24 -87
  4. data/bin/af +7 -2
  5. data/lib/af/version.rb +3 -0
  6. data/lib/vmc.rb +7 -2
  7. data/lib/vmc/cli.rb +475 -0
  8. data/lib/vmc/cli/app/app.rb +45 -0
  9. data/lib/vmc/cli/app/apps.rb +105 -0
  10. data/lib/vmc/cli/app/base.rb +82 -0
  11. data/lib/vmc/cli/app/crashes.rb +46 -0
  12. data/lib/vmc/cli/app/delete.rb +95 -0
  13. data/lib/vmc/cli/app/deprecated.rb +11 -0
  14. data/lib/vmc/cli/app/env.rb +78 -0
  15. data/lib/vmc/cli/app/files.rb +137 -0
  16. data/lib/vmc/cli/app/health.rb +26 -0
  17. data/lib/vmc/cli/app/instances.rb +53 -0
  18. data/lib/vmc/cli/app/logs.rb +76 -0
  19. data/lib/vmc/cli/app/push.rb +107 -0
  20. data/lib/vmc/cli/app/push/create.rb +150 -0
  21. data/lib/vmc/cli/app/push/interactions.rb +100 -0
  22. data/lib/vmc/cli/app/push/sync.rb +64 -0
  23. data/lib/vmc/cli/app/rename.rb +39 -0
  24. data/lib/vmc/cli/app/restart.rb +20 -0
  25. data/lib/vmc/cli/app/scale.rb +71 -0
  26. data/lib/vmc/cli/app/start.rb +93 -0
  27. data/lib/vmc/cli/app/stats.rb +67 -0
  28. data/lib/vmc/cli/app/stop.rb +27 -0
  29. data/lib/vmc/cli/domain/base.rb +12 -0
  30. data/lib/vmc/cli/domain/domains.rb +40 -0
  31. data/lib/vmc/cli/domain/map.rb +55 -0
  32. data/lib/vmc/cli/domain/unmap.rb +56 -0
  33. data/lib/vmc/cli/help.rb +16 -0
  34. data/lib/vmc/cli/interactive.rb +105 -0
  35. data/lib/vmc/cli/organization/base.rb +14 -0
  36. data/lib/vmc/cli/organization/create.rb +32 -0
  37. data/lib/vmc/cli/organization/delete.rb +73 -0
  38. data/lib/vmc/cli/organization/org.rb +45 -0
  39. data/lib/vmc/cli/organization/orgs.rb +35 -0
  40. data/lib/vmc/cli/organization/rename.rb +36 -0
  41. data/lib/vmc/cli/route/base.rb +12 -0
  42. data/lib/vmc/cli/route/map.rb +80 -0
  43. data/lib/vmc/cli/route/routes.rb +26 -0
  44. data/lib/vmc/cli/route/unmap.rb +94 -0
  45. data/lib/vmc/cli/service/base.rb +8 -0
  46. data/lib/vmc/cli/service/bind.rb +44 -0
  47. data/lib/vmc/cli/service/create.rb +126 -0
  48. data/lib/vmc/cli/service/delete.rb +86 -0
  49. data/lib/vmc/cli/service/rename.rb +35 -0
  50. data/lib/vmc/cli/service/service.rb +42 -0
  51. data/lib/vmc/cli/service/services.rb +115 -0
  52. data/lib/vmc/cli/service/unbind.rb +38 -0
  53. data/lib/vmc/cli/space/base.rb +21 -0
  54. data/lib/vmc/cli/space/create.rb +56 -0
  55. data/lib/vmc/cli/space/delete.rb +95 -0
  56. data/lib/vmc/cli/space/rename.rb +39 -0
  57. data/lib/vmc/cli/space/space.rb +64 -0
  58. data/lib/vmc/cli/space/spaces.rb +55 -0
  59. data/lib/vmc/cli/space/take.rb +16 -0
  60. data/lib/vmc/cli/start/base.rb +80 -0
  61. data/lib/vmc/cli/start/colors.rb +13 -0
  62. data/lib/vmc/cli/start/info.rb +122 -0
  63. data/lib/vmc/cli/start/login.rb +92 -0
  64. data/lib/vmc/cli/start/logout.rb +13 -0
  65. data/lib/vmc/cli/start/target.rb +64 -0
  66. data/lib/vmc/cli/start/target_interactions.rb +37 -0
  67. data/lib/vmc/cli/start/targets.rb +16 -0
  68. data/lib/vmc/cli/user/base.rb +29 -0
  69. data/lib/vmc/cli/user/create.rb +39 -0
  70. data/lib/vmc/cli/user/delete.rb +25 -0
  71. data/lib/vmc/cli/user/passwd.rb +50 -0
  72. data/lib/vmc/cli/user/register.rb +42 -0
  73. data/lib/vmc/cli/user/users.rb +32 -0
  74. data/lib/vmc/constants.rb +13 -0
  75. data/lib/vmc/detect.rb +134 -0
  76. data/lib/vmc/errors.rb +17 -0
  77. data/lib/vmc/plugin.rb +56 -0
  78. data/lib/vmc/spacing.rb +89 -0
  79. data/lib/vmc/spec_helper.rb +1 -0
  80. data/lib/vmc/test_support.rb +4 -0
  81. data/lib/vmc/test_support/command_helper.rb +32 -0
  82. data/lib/vmc/test_support/common_input_examples.rb +14 -0
  83. data/lib/vmc/test_support/fake_home_dir.rb +16 -0
  84. data/lib/vmc/test_support/interact_helper.rb +29 -0
  85. data/lib/vmc/version.rb +3 -0
  86. data/spec/assets/hello-sinatra/Gemfile +3 -0
  87. data/spec/assets/hello-sinatra/main.rb +6 -0
  88. data/spec/features/new_user_flow_spec.rb +71 -0
  89. data/spec/spec_helper.rb +63 -0
  90. data/spec/vmc/cli/app/base_spec.rb +17 -0
  91. data/spec/vmc/cli/app/delete_spec.rb +188 -0
  92. data/spec/vmc/cli/app/instances_spec.rb +65 -0
  93. data/spec/vmc/cli/app/push/create_spec.rb +571 -0
  94. data/spec/vmc/cli/app/push_spec.rb +369 -0
  95. data/spec/vmc/cli/app/rename_spec.rb +104 -0
  96. data/spec/vmc/cli/app/scale_spec.rb +81 -0
  97. data/spec/vmc/cli/app/stats_spec.rb +62 -0
  98. data/spec/vmc/cli/domain/map_spec.rb +140 -0
  99. data/spec/vmc/cli/domain/unmap_spec.rb +73 -0
  100. data/spec/vmc/cli/organization/orgs_spec.rb +108 -0
  101. data/spec/vmc/cli/organization/rename_spec.rb +113 -0
  102. data/spec/vmc/cli/route/map_spec.rb +138 -0
  103. data/spec/vmc/cli/route/unmap_spec.rb +215 -0
  104. data/spec/vmc/cli/service/bind_spec.rb +25 -0
  105. data/spec/vmc/cli/service/delete_spec.rb +22 -0
  106. data/spec/vmc/cli/service/rename_spec.rb +105 -0
  107. data/spec/vmc/cli/service/service_spec.rb +23 -0
  108. data/spec/vmc/cli/service/unbind_spec.rb +25 -0
  109. data/spec/vmc/cli/space/rename_spec.rb +102 -0
  110. data/spec/vmc/cli/space/spaces_spec.rb +104 -0
  111. data/spec/vmc/cli/start/info_spec.rb +153 -0
  112. data/spec/vmc/cli/start/login_spec.rb +71 -0
  113. data/spec/vmc/cli/user/create_spec.rb +54 -0
  114. data/spec/vmc/cli/user/passwd_spec.rb +102 -0
  115. data/spec/vmc/cli/user/register_spec.rb +148 -0
  116. data/spec/vmc/cli_spec.rb +448 -0
  117. data/spec/vmc/detect_spec.rb +54 -0
  118. metadata +231 -124
  119. data/README.md +0 -155
  120. data/caldecott_helper/Gemfile +0 -10
  121. data/caldecott_helper/Gemfile.lock +0 -48
  122. data/caldecott_helper/server.rb +0 -43
  123. data/config/clients.yml +0 -17
  124. data/config/micro/offline.conf +0 -2
  125. data/config/micro/paths.yml +0 -22
  126. data/config/micro/refresh_ip.rb +0 -20
  127. data/lib/cli.rb +0 -48
  128. data/lib/cli/commands/admin.rb +0 -81
  129. data/lib/cli/commands/apps.rb +0 -1358
  130. data/lib/cli/commands/base.rb +0 -233
  131. data/lib/cli/commands/manifest.rb +0 -56
  132. data/lib/cli/commands/micro.rb +0 -115
  133. data/lib/cli/commands/misc.rb +0 -147
  134. data/lib/cli/commands/services.rb +0 -217
  135. data/lib/cli/commands/user.rb +0 -70
  136. data/lib/cli/config.rb +0 -176
  137. data/lib/cli/console_helper.rb +0 -163
  138. data/lib/cli/core_ext.rb +0 -122
  139. data/lib/cli/errors.rb +0 -19
  140. data/lib/cli/file_helper.rb +0 -123
  141. data/lib/cli/frameworks.rb +0 -265
  142. data/lib/cli/manifest_helper.rb +0 -316
  143. data/lib/cli/runner.rb +0 -633
  144. data/lib/cli/services_helper.rb +0 -104
  145. data/lib/cli/tunnel_helper.rb +0 -336
  146. data/lib/cli/usage.rb +0 -129
  147. data/lib/cli/version.rb +0 -7
  148. data/lib/cli/zip_util.rb +0 -102
  149. data/lib/vmc/client.rb +0 -574
  150. data/lib/vmc/const.rb +0 -27
  151. data/lib/vmc/micro.rb +0 -56
  152. data/lib/vmc/micro/switcher/base.rb +0 -97
  153. data/lib/vmc/micro/switcher/darwin.rb +0 -19
  154. data/lib/vmc/micro/switcher/dummy.rb +0 -15
  155. data/lib/vmc/micro/switcher/linux.rb +0 -16
  156. data/lib/vmc/micro/switcher/windows.rb +0 -31
  157. data/lib/vmc/micro/vmrun.rb +0 -158
@@ -0,0 +1,27 @@
1
+ require "vmc/cli/app/base"
2
+
3
+ module VMC::App
4
+ class Stop < Base
5
+ desc "Stop an application"
6
+ group :apps, :manage
7
+ input :apps, :desc => "Applications to start", :argument => :splat,
8
+ :singular => :app, :from_given => by_name(:app)
9
+ input :all, :desc => "Stop all applications", :default => false
10
+ def stop
11
+ apps = input[:all] ? client.apps : input[:apps]
12
+ fail "No applications given." if apps.empty?
13
+
14
+ apps.each do |app|
15
+ with_progress("Stopping #{c(app.name, :name)}") do |s|
16
+ if app.stopped?
17
+ s.skip do
18
+ err "Application is not running."
19
+ end
20
+ end
21
+
22
+ app.stop!
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ require "vmc/cli"
2
+
3
+ module VMC
4
+ module Domain
5
+ class Base < CLI
6
+ def precondition
7
+ super
8
+ fail "This command is v2-only." unless v2?
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ require "vmc/cli/domain/base"
2
+
3
+ module VMC::Domain
4
+ class Domains < Base
5
+ desc "List domains in a space"
6
+ group :domains, :hidden => true
7
+ input :space, :desc => "Space to list the domains from",
8
+ :argument => :optional, :default => proc { client.current_space },
9
+ :from_given => by_name(:space)
10
+ input :all, :desc => "List all domains", :default => false
11
+ def domains
12
+ space = input[:space]
13
+
14
+ domains =
15
+ if input[:all]
16
+ with_progress("Getting all domains") do
17
+ client.domains
18
+ end
19
+ else
20
+ with_progress("Getting domains in #{c(space.name, :name)}") do
21
+ space.domains
22
+ end
23
+ end
24
+
25
+ line unless quiet?
26
+
27
+ table(
28
+ %w{name owner},
29
+ domains.sort_by(&:name).collect { |r|
30
+ [c(r.name, :name),
31
+ if org = r.owning_organization
32
+ c(org.name, :name)
33
+ else
34
+ d("none")
35
+ end
36
+ ]
37
+ })
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ require "vmc/cli/domain/base"
2
+
3
+ module VMC::Domain
4
+ class Map < Base
5
+ desc "Map a domain to an organization or space"
6
+ group :domains, :hidden => true
7
+ input :name, :desc => "Domain to map", :argument => :required
8
+ input :organization, :desc => "Organization to map the domain to",
9
+ :aliases => %w{--org -o},
10
+ :default => proc { client.current_organization },
11
+ :from_given => by_name(:organization)
12
+ input :space, :desc => "Space to map the domain to",
13
+ :default => proc { client.current_space },
14
+ :from_given => by_name(:space)
15
+ input :shared, :desc => "Create a shared domain", :default => false
16
+ def map_domain
17
+ domain = client.domain_by_name(input[:name])
18
+
19
+ given_org = input.has?(:organization)
20
+ given_space = input.has?(:space)
21
+
22
+ org = input[:organization]
23
+ space = input[:space]
24
+
25
+ given_space = true unless given_org || given_space
26
+
27
+ unless domain
28
+ domain = client.domain
29
+ domain.name = input[:name]
30
+ domain.owning_organization = org unless input[:shared]
31
+ domain.wildcard = true
32
+
33
+ with_progress("Creating domain #{c(domain.name, :name)}") do
34
+ domain.create!
35
+ org.add_domain(domain) if org && !given_org && !given_space
36
+ end
37
+ end
38
+
39
+ if given_space
40
+ add_domain(domain, space.organization)
41
+ add_domain(domain, space)
42
+ elsif given_org
43
+ add_domain(domain, org)
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def add_domain(domain, target)
50
+ with_progress("Mapping #{c(domain.name, :name)} to #{c(target.name, :name)}") do
51
+ target.add_domain(domain)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,56 @@
1
+ require "vmc/cli/domain/base"
2
+
3
+ module VMC::Domain
4
+ class Unmap < Base
5
+ desc "Unmap a domain from an organization or space"
6
+ group :domains, :hidden => true
7
+ input :domain, :desc => "Domain to unmap", :argument => :required,
8
+ :from_given => by_name("domain")
9
+ input :organization, :desc => "Organization to unmap the domain from",
10
+ :aliases => %w{--org -o},
11
+ :default => proc { client.current_organization },
12
+ :from_given => by_name(:organization)
13
+ input :space, :desc => "Space to unmap the domain from",
14
+ :default => proc { client.current_space },
15
+ :from_given => by_name(:space)
16
+ input :delete, :desc => "Delete domain", :type => :boolean
17
+ input :really, :type => :boolean, :forget => true, :hidden => true,
18
+ :default => proc { force? || interact }
19
+ def unmap_domain
20
+ domain = input[:domain]
21
+
22
+ given_org = input.has?(:organization)
23
+ given_space = input.has?(:space)
24
+
25
+ org = input[:organization]
26
+ space = input[:space]
27
+
28
+ if input[:delete]
29
+ return unless input[:really, domain.name, :name]
30
+
31
+ with_progress("Deleting domain #{c(domain.name, :name)}") do
32
+ domain.delete!
33
+ end
34
+
35
+ return
36
+ end
37
+
38
+ given_space = true unless given_org || given_space
39
+
40
+ remove_domain(domain, space) if given_space
41
+ remove_domain(domain, org) if given_org
42
+ end
43
+
44
+ private
45
+
46
+ def remove_domain(domain, target)
47
+ with_progress("Unmapping #{c(domain.name, :name)} from #{c(target.name, :name)}") do
48
+ target.remove_domain(domain)
49
+ end
50
+ end
51
+
52
+ def ask_really(name, color)
53
+ ask("Really delete #{c(name, color)}?", :default => false)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,16 @@
1
+ require "mothership/help"
2
+
3
+ Mothership::Help.groups(
4
+ [:start, "Getting Started"],
5
+ [:apps, "Applications",
6
+ [:manage, "Management"],
7
+ [:info, "Information"]],
8
+ [:services, "Services",
9
+ [:manage, "Management"]],
10
+ [:organizations, "Organizations"],
11
+ [:spaces, "Spaces"],
12
+ [:routes, "Routes"],
13
+ [:system, "System"],
14
+ [:domains, "Domains"],
15
+ [:admin, "Administration",
16
+ [:user, "User Management"]])
@@ -0,0 +1,105 @@
1
+ require "interact"
2
+ require "interact/pretty"
3
+ require "interact/progress"
4
+
5
+ module VMC
6
+ module Interactive
7
+ include ::Interactive::Rewindable
8
+ include Interact::Pretty
9
+ include Interact::Progress
10
+
11
+ def ask(question, options = {})
12
+ if force? and options.key?(:default)
13
+ options[:default]
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def list_choices(choices, options = {})
20
+ choices.each_with_index do |o, i|
21
+ puts "#{c(i + 1, :number)}: #{show_choice(o, options)}"
22
+ end
23
+ end
24
+
25
+ def input_state(options)
26
+ if options.key? :default
27
+ answer = show_default(options)
28
+ end
29
+
30
+ CFState.new(options, answer)
31
+ end
32
+
33
+ def show_default(options)
34
+ case options[:default]
35
+ when true
36
+ "y"
37
+ when false
38
+ "n"
39
+ when nil
40
+ ""
41
+ else
42
+ show_choice(options[:default], options)
43
+ end
44
+ end
45
+
46
+ def prompt(question, options)
47
+ value = show_default(options)
48
+
49
+ print "#{question}"
50
+ print c("> ", :prompt)
51
+
52
+ unless value.empty?
53
+ print "#{d(value) + "\b" * value.size}"
54
+ end
55
+ end
56
+
57
+ def handler(event, state)
58
+ ans = state.answer
59
+ pos = state.position
60
+
61
+ exit if event == :eof
62
+
63
+ if state.default?
64
+ if event.is_a?(Array) and event[0] == :key
65
+ # initial non-movement keypress clears default answer
66
+ clear_input(state)
67
+ else
68
+ # wipe away any coloring
69
+ redraw_input(state)
70
+ end
71
+
72
+ state.clear_default!
73
+
74
+ # tab with a default accepts it and moves to the end
75
+ if event == :tab
76
+ state.goto(ans.size)
77
+ else
78
+ super
79
+ end
80
+ else
81
+ super
82
+ end
83
+
84
+ print "\n" if event == :enter
85
+ end
86
+
87
+ class CFState < ::Interactive::InputState
88
+ def initialize(options = {}, answer = nil, position = 0)
89
+ @options = options
90
+ @answer = answer || ""
91
+ @default = options.key? :default
92
+ @position = position
93
+ @done = false
94
+ end
95
+
96
+ def clear_default!
97
+ @default = false
98
+ end
99
+
100
+ def default?
101
+ @default
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,14 @@
1
+ require "vmc/cli"
2
+
3
+ module VMC
4
+ module Organization
5
+ class Base < CLI
6
+ def precondition
7
+ check_target
8
+ check_logged_in
9
+
10
+ fail "This command is v2-only." unless v2?
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ require "vmc/cli/organization/base"
2
+
3
+ module VMC::Organization
4
+ class Create < Base
5
+ desc "Create an organization"
6
+ group :organizations, :hidden => true
7
+ input :name, :desc => "Organization name", :argument => :optional
8
+ input :target, :desc => "Switch to the organization after creation",
9
+ :alias => "-t", :default => true
10
+ input :add_self, :desc => "Add yourself to the organization",
11
+ :default => true
12
+ def create_org
13
+ org = client.organization
14
+ org.name = input[:name]
15
+ org.users = [client.current_user] if input[:add_self]
16
+
17
+ with_progress("Creating organization #{c(org.name, :name)}") do
18
+ org.create!
19
+ end
20
+
21
+ if input[:target]
22
+ invoke :target, :organization => org
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def ask_name
29
+ ask("Name")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,73 @@
1
+ require "vmc/cli/organization/base"
2
+
3
+ module VMC::Organization
4
+ class Delete < Base
5
+ desc "Delete an organization"
6
+ group :organizations, :hidden => true
7
+ input :organization, :desc => "Organization to delete",
8
+ :aliases => %w{--org -o}, :argument => :optional,
9
+ :from_given => by_name(:organization)
10
+ input :recursive, :desc => "Delete recursively", :alias => "-r",
11
+ :default => false, :forget => true
12
+ input :warn, :desc => "Show warning if it was the last org",
13
+ :default => true
14
+ input :really, :type => :boolean, :forget => true, :hidden => true,
15
+ :default => proc { force? || interact }
16
+ def delete_org
17
+ org = input[:organization]
18
+ return unless input[:really, org]
19
+
20
+ spaces = org.spaces
21
+ unless spaces.empty?
22
+ unless force?
23
+ line "This organization is not empty!"
24
+ line
25
+ line "spaces: #{name_list(spaces)}"
26
+ line
27
+
28
+ return unless input[:recursive]
29
+ end
30
+
31
+ spaces.each do |s|
32
+ invoke :delete_space, :space => s, :really => true,
33
+ :recursive => true, :warn => false
34
+ end
35
+ end
36
+
37
+ is_current = org == client.current_organization
38
+
39
+ with_progress("Deleting organization #{c(org.name, :name)}") do
40
+ org.delete!
41
+ end
42
+
43
+ if orgs.size == 1
44
+ return unless input[:warn]
45
+
46
+ line
47
+ line c("There are no longer any organizations.", :warning)
48
+ line "You may want to create one with #{c("create-org", :good)}."
49
+ elsif is_current
50
+ invalidate_target
51
+ invoke :target
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def ask_organization
58
+ orgs = client.organizations
59
+ fail "No organizations." if orgs.empty?
60
+
61
+ ask("Which organization", :choices => orgs.sort_by(&:name),
62
+ :display => proc(&:name))
63
+ end
64
+
65
+ def ask_really(org)
66
+ ask("Really delete #{c(org.name, :name)}?", :default => false)
67
+ end
68
+
69
+ def ask_recursive
70
+ ask "Delete #{c("EVERYTHING", :bad)}?", :default => false
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,45 @@
1
+ require "vmc/cli/organization/base"
2
+
3
+ module VMC::Organization
4
+ class Org < Base
5
+ desc "Show organization information"
6
+ group :organizations, :hidden => true
7
+ input :organization, :desc => "Organization to show",
8
+ :aliases => %w{--org -o}, :argument => :optional,
9
+ :from_given => by_name(:organization),
10
+ :default => proc { client.current_organization }
11
+ input :full, :desc => "Show full information for spaces, domains, etc.",
12
+ :default => false
13
+ def org
14
+ org = input[:organization]
15
+
16
+ unless org
17
+ return if quiet?
18
+ fail "No current organization."
19
+ end
20
+
21
+ if quiet?
22
+ puts org.name
23
+ return
24
+ end
25
+
26
+ line "#{c(org.name, :name)}:"
27
+
28
+ indented do
29
+ line "domains: #{name_list(org.domains)}"
30
+
31
+ if input[:full]
32
+ line "spaces:"
33
+
34
+ spaced(org.spaces(:depth => 2)) do |s|
35
+ indented do
36
+ invoke :space, :space => s
37
+ end
38
+ end
39
+ else
40
+ line "spaces: #{name_list(org.spaces)}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end