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.
- checksums.yaml +14 -6
- data/LICENSE +1277 -24
- data/Rakefile +24 -87
- data/bin/af +7 -2
- data/lib/af/version.rb +3 -0
- data/lib/vmc.rb +7 -2
- data/lib/vmc/cli.rb +475 -0
- data/lib/vmc/cli/app/app.rb +45 -0
- data/lib/vmc/cli/app/apps.rb +105 -0
- data/lib/vmc/cli/app/base.rb +82 -0
- data/lib/vmc/cli/app/crashes.rb +46 -0
- data/lib/vmc/cli/app/delete.rb +95 -0
- data/lib/vmc/cli/app/deprecated.rb +11 -0
- data/lib/vmc/cli/app/env.rb +78 -0
- data/lib/vmc/cli/app/files.rb +137 -0
- data/lib/vmc/cli/app/health.rb +26 -0
- data/lib/vmc/cli/app/instances.rb +53 -0
- data/lib/vmc/cli/app/logs.rb +76 -0
- data/lib/vmc/cli/app/push.rb +107 -0
- data/lib/vmc/cli/app/push/create.rb +150 -0
- data/lib/vmc/cli/app/push/interactions.rb +100 -0
- data/lib/vmc/cli/app/push/sync.rb +64 -0
- data/lib/vmc/cli/app/rename.rb +39 -0
- data/lib/vmc/cli/app/restart.rb +20 -0
- data/lib/vmc/cli/app/scale.rb +71 -0
- data/lib/vmc/cli/app/start.rb +93 -0
- data/lib/vmc/cli/app/stats.rb +67 -0
- data/lib/vmc/cli/app/stop.rb +27 -0
- data/lib/vmc/cli/domain/base.rb +12 -0
- data/lib/vmc/cli/domain/domains.rb +40 -0
- data/lib/vmc/cli/domain/map.rb +55 -0
- data/lib/vmc/cli/domain/unmap.rb +56 -0
- data/lib/vmc/cli/help.rb +16 -0
- data/lib/vmc/cli/interactive.rb +105 -0
- data/lib/vmc/cli/organization/base.rb +14 -0
- data/lib/vmc/cli/organization/create.rb +32 -0
- data/lib/vmc/cli/organization/delete.rb +73 -0
- data/lib/vmc/cli/organization/org.rb +45 -0
- data/lib/vmc/cli/organization/orgs.rb +35 -0
- data/lib/vmc/cli/organization/rename.rb +36 -0
- data/lib/vmc/cli/route/base.rb +12 -0
- data/lib/vmc/cli/route/map.rb +80 -0
- data/lib/vmc/cli/route/routes.rb +26 -0
- data/lib/vmc/cli/route/unmap.rb +94 -0
- data/lib/vmc/cli/service/base.rb +8 -0
- data/lib/vmc/cli/service/bind.rb +44 -0
- data/lib/vmc/cli/service/create.rb +126 -0
- data/lib/vmc/cli/service/delete.rb +86 -0
- data/lib/vmc/cli/service/rename.rb +35 -0
- data/lib/vmc/cli/service/service.rb +42 -0
- data/lib/vmc/cli/service/services.rb +115 -0
- data/lib/vmc/cli/service/unbind.rb +38 -0
- data/lib/vmc/cli/space/base.rb +21 -0
- data/lib/vmc/cli/space/create.rb +56 -0
- data/lib/vmc/cli/space/delete.rb +95 -0
- data/lib/vmc/cli/space/rename.rb +39 -0
- data/lib/vmc/cli/space/space.rb +64 -0
- data/lib/vmc/cli/space/spaces.rb +55 -0
- data/lib/vmc/cli/space/take.rb +16 -0
- data/lib/vmc/cli/start/base.rb +80 -0
- data/lib/vmc/cli/start/colors.rb +13 -0
- data/lib/vmc/cli/start/info.rb +122 -0
- data/lib/vmc/cli/start/login.rb +92 -0
- data/lib/vmc/cli/start/logout.rb +13 -0
- data/lib/vmc/cli/start/target.rb +64 -0
- data/lib/vmc/cli/start/target_interactions.rb +37 -0
- data/lib/vmc/cli/start/targets.rb +16 -0
- data/lib/vmc/cli/user/base.rb +29 -0
- data/lib/vmc/cli/user/create.rb +39 -0
- data/lib/vmc/cli/user/delete.rb +25 -0
- data/lib/vmc/cli/user/passwd.rb +50 -0
- data/lib/vmc/cli/user/register.rb +42 -0
- data/lib/vmc/cli/user/users.rb +32 -0
- data/lib/vmc/constants.rb +13 -0
- data/lib/vmc/detect.rb +134 -0
- data/lib/vmc/errors.rb +17 -0
- data/lib/vmc/plugin.rb +56 -0
- data/lib/vmc/spacing.rb +89 -0
- data/lib/vmc/spec_helper.rb +1 -0
- data/lib/vmc/test_support.rb +4 -0
- data/lib/vmc/test_support/command_helper.rb +32 -0
- data/lib/vmc/test_support/common_input_examples.rb +14 -0
- data/lib/vmc/test_support/fake_home_dir.rb +16 -0
- data/lib/vmc/test_support/interact_helper.rb +29 -0
- data/lib/vmc/version.rb +3 -0
- data/spec/assets/hello-sinatra/Gemfile +3 -0
- data/spec/assets/hello-sinatra/main.rb +6 -0
- data/spec/features/new_user_flow_spec.rb +71 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/vmc/cli/app/base_spec.rb +17 -0
- data/spec/vmc/cli/app/delete_spec.rb +188 -0
- data/spec/vmc/cli/app/instances_spec.rb +65 -0
- data/spec/vmc/cli/app/push/create_spec.rb +571 -0
- data/spec/vmc/cli/app/push_spec.rb +369 -0
- data/spec/vmc/cli/app/rename_spec.rb +104 -0
- data/spec/vmc/cli/app/scale_spec.rb +81 -0
- data/spec/vmc/cli/app/stats_spec.rb +62 -0
- data/spec/vmc/cli/domain/map_spec.rb +140 -0
- data/spec/vmc/cli/domain/unmap_spec.rb +73 -0
- data/spec/vmc/cli/organization/orgs_spec.rb +108 -0
- data/spec/vmc/cli/organization/rename_spec.rb +113 -0
- data/spec/vmc/cli/route/map_spec.rb +138 -0
- data/spec/vmc/cli/route/unmap_spec.rb +215 -0
- data/spec/vmc/cli/service/bind_spec.rb +25 -0
- data/spec/vmc/cli/service/delete_spec.rb +22 -0
- data/spec/vmc/cli/service/rename_spec.rb +105 -0
- data/spec/vmc/cli/service/service_spec.rb +23 -0
- data/spec/vmc/cli/service/unbind_spec.rb +25 -0
- data/spec/vmc/cli/space/rename_spec.rb +102 -0
- data/spec/vmc/cli/space/spaces_spec.rb +104 -0
- data/spec/vmc/cli/start/info_spec.rb +153 -0
- data/spec/vmc/cli/start/login_spec.rb +71 -0
- data/spec/vmc/cli/user/create_spec.rb +54 -0
- data/spec/vmc/cli/user/passwd_spec.rb +102 -0
- data/spec/vmc/cli/user/register_spec.rb +148 -0
- data/spec/vmc/cli_spec.rb +448 -0
- data/spec/vmc/detect_spec.rb +54 -0
- metadata +231 -124
- data/README.md +0 -155
- data/caldecott_helper/Gemfile +0 -10
- data/caldecott_helper/Gemfile.lock +0 -48
- data/caldecott_helper/server.rb +0 -43
- data/config/clients.yml +0 -17
- data/config/micro/offline.conf +0 -2
- data/config/micro/paths.yml +0 -22
- data/config/micro/refresh_ip.rb +0 -20
- data/lib/cli.rb +0 -48
- data/lib/cli/commands/admin.rb +0 -81
- data/lib/cli/commands/apps.rb +0 -1358
- data/lib/cli/commands/base.rb +0 -233
- data/lib/cli/commands/manifest.rb +0 -56
- data/lib/cli/commands/micro.rb +0 -115
- data/lib/cli/commands/misc.rb +0 -147
- data/lib/cli/commands/services.rb +0 -217
- data/lib/cli/commands/user.rb +0 -70
- data/lib/cli/config.rb +0 -176
- data/lib/cli/console_helper.rb +0 -163
- data/lib/cli/core_ext.rb +0 -122
- data/lib/cli/errors.rb +0 -19
- data/lib/cli/file_helper.rb +0 -123
- data/lib/cli/frameworks.rb +0 -265
- data/lib/cli/manifest_helper.rb +0 -316
- data/lib/cli/runner.rb +0 -633
- data/lib/cli/services_helper.rb +0 -104
- data/lib/cli/tunnel_helper.rb +0 -336
- data/lib/cli/usage.rb +0 -129
- data/lib/cli/version.rb +0 -7
- data/lib/cli/zip_util.rb +0 -102
- data/lib/vmc/client.rb +0 -574
- data/lib/vmc/const.rb +0 -27
- data/lib/vmc/micro.rb +0 -56
- data/lib/vmc/micro/switcher/base.rb +0 -97
- data/lib/vmc/micro/switcher/darwin.rb +0 -19
- data/lib/vmc/micro/switcher/dummy.rb +0 -15
- data/lib/vmc/micro/switcher/linux.rb +0 -16
- data/lib/vmc/micro/switcher/windows.rb +0 -31
- data/lib/vmc/micro/vmrun.rb +0 -158
@@ -0,0 +1,86 @@
|
|
1
|
+
require "vmc/cli/service/base"
|
2
|
+
|
3
|
+
module VMC::Service
|
4
|
+
class Delete < Base
|
5
|
+
desc "Delete a service"
|
6
|
+
group :services, :manage
|
7
|
+
input :service, :desc => "Service to bind", :argument => :optional,
|
8
|
+
:from_given => by_name(:service_instance, :service)
|
9
|
+
input :unbind, :desc => "Unbind from applications before deleting?",
|
10
|
+
:type => :boolean, :default => proc { force? || interact }
|
11
|
+
input :all, :desc => "Delete all services", :default => false
|
12
|
+
input :really, :type => :boolean, :forget => true, :hidden => true,
|
13
|
+
:default => proc { force? || interact }
|
14
|
+
def delete_service
|
15
|
+
if input[:all]
|
16
|
+
return unless input[:really, "ALL SERVICES", :bad]
|
17
|
+
|
18
|
+
client.service_instances.each do |i|
|
19
|
+
invoke :delete_service, :service => i, :really => true
|
20
|
+
end
|
21
|
+
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
service = input[:service]
|
26
|
+
|
27
|
+
return unless input[:really, service.name, :name]
|
28
|
+
|
29
|
+
bindings = []
|
30
|
+
|
31
|
+
if v2?
|
32
|
+
bindings = service.service_bindings
|
33
|
+
|
34
|
+
unless bindings.empty? || !input[:unbind, bindings.collect(&:app)]
|
35
|
+
bindings.each do |b|
|
36
|
+
invoke :unbind_service, :service => service, :app => b.app
|
37
|
+
end
|
38
|
+
|
39
|
+
bindings = []
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
with_progress("Deleting #{c(service.name, :name)}") do |s|
|
44
|
+
if bindings.empty?
|
45
|
+
service.delete!
|
46
|
+
else
|
47
|
+
s.skip do
|
48
|
+
apps = bindings.collect(&:app).collect { |a| b(a.name) }
|
49
|
+
err "Service is bound to #{human_list(apps)}."
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def ask_service
|
58
|
+
services = client.service_instances
|
59
|
+
fail "No services." if services.empty?
|
60
|
+
|
61
|
+
ask "Which service?", :choices => services,
|
62
|
+
:display => proc(&:name)
|
63
|
+
end
|
64
|
+
|
65
|
+
def ask_unbind(apps)
|
66
|
+
names = human_list(apps.collect { |a| c(a.name, :name) })
|
67
|
+
|
68
|
+
ask("Unbind from #{names} before deleting?", :default => true)
|
69
|
+
end
|
70
|
+
|
71
|
+
def ask_really(name, color)
|
72
|
+
ask("Really delete #{c(name, color)}?", :default => false)
|
73
|
+
end
|
74
|
+
|
75
|
+
def human_list(xs)
|
76
|
+
if xs.size == 1
|
77
|
+
xs.first
|
78
|
+
elsif xs.size == 2
|
79
|
+
"#{xs.first} and #{xs.last}"
|
80
|
+
else
|
81
|
+
last = xs.pop
|
82
|
+
xs.join(", ") + ", and #{last}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "vmc/cli/service/base"
|
2
|
+
|
3
|
+
module VMC::Service
|
4
|
+
class Rename < Base
|
5
|
+
desc "Rename a service"
|
6
|
+
group :services, :manage, :hidden => true
|
7
|
+
input :service, :desc => "Service to rename", :argument => :optional,
|
8
|
+
:from_given => by_name(:service_instance, :service)
|
9
|
+
input :name, :desc => "New service name", :argument => :optional
|
10
|
+
def rename_service
|
11
|
+
service = input[:service]
|
12
|
+
name = input[:name]
|
13
|
+
|
14
|
+
service.name = name
|
15
|
+
|
16
|
+
with_progress("Renaming to #{c(name, :name)}") do
|
17
|
+
service.update!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def ask_service
|
24
|
+
services = client.service_instances
|
25
|
+
fail "No services." if services.empty?
|
26
|
+
|
27
|
+
ask("Rename which service?", :choices => services.sort_by(&:name),
|
28
|
+
:display => proc(&:name))
|
29
|
+
end
|
30
|
+
|
31
|
+
def ask_name
|
32
|
+
ask("New name")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "vmc/cli/service/base"
|
2
|
+
|
3
|
+
module VMC::Service
|
4
|
+
class Service < Base
|
5
|
+
desc "Show service information"
|
6
|
+
group :services
|
7
|
+
input :service, :desc => "Service to show", :argument => :required,
|
8
|
+
:from_given => by_name(:service_instance, :service)
|
9
|
+
def service
|
10
|
+
display_service(input[:service])
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def display_service(i)
|
16
|
+
if quiet?
|
17
|
+
line i.name
|
18
|
+
elsif v2?
|
19
|
+
plan = i.service_plan
|
20
|
+
service = plan.service
|
21
|
+
|
22
|
+
apps = i.service_bindings.collect { |b|
|
23
|
+
c(b.app.name, :name)
|
24
|
+
}.join(", ")
|
25
|
+
|
26
|
+
line "#{c(i.name, :name)}: #{service.label} #{service.version}"
|
27
|
+
|
28
|
+
indented do
|
29
|
+
line "provider: #{c(service.provider, :name)}"
|
30
|
+
line "bound to: #{apps}" unless apps.empty?
|
31
|
+
line "plan: #{c(plan.name, :name)}"
|
32
|
+
|
33
|
+
indented do
|
34
|
+
line "description: #{plan.description}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
line "#{c(i.name, :name)}: #{i.vendor} #{i.version}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require "vmc/cli/service/base"
|
2
|
+
|
3
|
+
module VMC::Service
|
4
|
+
class Services < Base
|
5
|
+
desc "List your service"
|
6
|
+
group :services
|
7
|
+
input :space, :desc => "Show services in given space",
|
8
|
+
:from_given => by_name(:space),
|
9
|
+
:default => proc { client.current_space }
|
10
|
+
input :name, :desc => "Filter by name"
|
11
|
+
input :service, :desc => "Filter by service type"
|
12
|
+
input :plan, :desc => "Filter by service plan"
|
13
|
+
input :provider, :desc => "Filter by service provider"
|
14
|
+
input :version, :desc => "Filter by service version"
|
15
|
+
input :app, :desc => "Limit to application's service bindings",
|
16
|
+
:from_given => by_name(:app)
|
17
|
+
input :full, :desc => "Verbose output format", :default => false
|
18
|
+
def services
|
19
|
+
msg =
|
20
|
+
if space = input[:space]
|
21
|
+
"Getting services in #{c(space.name, :name)}"
|
22
|
+
else
|
23
|
+
"Getting services"
|
24
|
+
end
|
25
|
+
|
26
|
+
services =
|
27
|
+
with_progress(msg) do
|
28
|
+
client.service_instances(:depth => 2)
|
29
|
+
end
|
30
|
+
|
31
|
+
line unless quiet?
|
32
|
+
|
33
|
+
if services.empty? and !quiet?
|
34
|
+
line "No services."
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
services.reject! do |i|
|
39
|
+
!service_matches(i, input)
|
40
|
+
end
|
41
|
+
|
42
|
+
if input[:full]
|
43
|
+
spaced(services) do |s|
|
44
|
+
invoke :service, :service => s
|
45
|
+
end
|
46
|
+
else
|
47
|
+
table(
|
48
|
+
["name", "infra", "service", "version", v2? && "plan", v2? && "bound apps"],
|
49
|
+
services.collect { |i|
|
50
|
+
if v2?
|
51
|
+
plan = i.service_plan
|
52
|
+
service = plan.service
|
53
|
+
|
54
|
+
label = service.label
|
55
|
+
version = service.version
|
56
|
+
apps = name_list(i.service_bindings.collect(&:app))
|
57
|
+
else
|
58
|
+
label = i.vendor
|
59
|
+
version = i.version.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
[ c(i.name, :name),
|
63
|
+
c(i.infra.name, :infra),
|
64
|
+
label,
|
65
|
+
version,
|
66
|
+
v2? && plan.name,
|
67
|
+
apps
|
68
|
+
]
|
69
|
+
})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def service_matches(i, options)
|
76
|
+
if app = options[:app]
|
77
|
+
return false unless app.services.include? i
|
78
|
+
end
|
79
|
+
|
80
|
+
if name = options[:name]
|
81
|
+
return false unless File.fnmatch(name, i.name)
|
82
|
+
end
|
83
|
+
|
84
|
+
plan = i.service_plan if v2?
|
85
|
+
|
86
|
+
if service = options[:service]
|
87
|
+
if v2?
|
88
|
+
return false unless File.fnmatch(service, plan.service.label)
|
89
|
+
else
|
90
|
+
return false unless File.fnmatch(service, i.vendor)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
if plan = options[:plan]
|
95
|
+
fail "--plan is not supported on this target" unless v2?
|
96
|
+
return false unless File.fnmatch(plan.upcase, plan.name.upcase)
|
97
|
+
end
|
98
|
+
|
99
|
+
if provider = options[:provider]
|
100
|
+
fail "--provider is not supported on this target" unless v2?
|
101
|
+
return false unless File.fnmatch(provider, plan.service.provider)
|
102
|
+
end
|
103
|
+
|
104
|
+
if version = options[:version]
|
105
|
+
if v2?
|
106
|
+
return false unless File.fnmatch(version, plan.service.version)
|
107
|
+
else
|
108
|
+
return false unless File.fnmatch(version, i.version)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
true
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "vmc/detect"
|
2
|
+
|
3
|
+
require "vmc/cli/service/base"
|
4
|
+
|
5
|
+
module VMC::Service
|
6
|
+
class Unbind < Base
|
7
|
+
desc "Unbind a service from an application"
|
8
|
+
group :services, :manage
|
9
|
+
input :service, :desc => "Service to unbind", :argument => :optional,
|
10
|
+
:from_given => by_name(:service_instance, :service)
|
11
|
+
input :app, :desc => "Application to unbind from", :argument => :optional,
|
12
|
+
:from_given => by_name(:app)
|
13
|
+
def unbind_service
|
14
|
+
app = input[:app]
|
15
|
+
service = input[:service, app]
|
16
|
+
|
17
|
+
with_progress(
|
18
|
+
"Unbinding #{c(service.name, :name)} from #{c(app.name, :name)}") do
|
19
|
+
app.unbind(service)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def ask_service(app)
|
26
|
+
services = app.services
|
27
|
+
fail "No bound services." if services.empty?
|
28
|
+
|
29
|
+
ask "Which service?", :choices => services,
|
30
|
+
:display => proc(&:name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def ask_app
|
34
|
+
ask "Which application?", :choices => client.apps,
|
35
|
+
:display => proc(&:name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "vmc/cli"
|
2
|
+
|
3
|
+
module VMC
|
4
|
+
module Space
|
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
|
+
|
13
|
+
def self.space_by_name
|
14
|
+
proc { |name, org, *_|
|
15
|
+
org.space_by_name(name) ||
|
16
|
+
fail("Unknown space '#{name}'.")
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "vmc/cli/space/base"
|
2
|
+
|
3
|
+
module VMC::Space
|
4
|
+
class Create < Base
|
5
|
+
desc "Create a space in an organization"
|
6
|
+
group :spaces, :hidden => true
|
7
|
+
input :name, :desc => "Space name", :argument => :optional
|
8
|
+
input :organization, :desc => "Parent organization",
|
9
|
+
:argument => :optional, :aliases => ["--org", "-o"],
|
10
|
+
:from_given => by_name(:organization),
|
11
|
+
:default => proc { client.current_organization }
|
12
|
+
input :target, :desc => "Switch to the space after creation",
|
13
|
+
:alias => "-t", :default => false
|
14
|
+
input :manager, :desc => "Add yourself as manager", :default => true
|
15
|
+
input :developer, :desc => "Add yourself as developer", :default => true
|
16
|
+
input :auditor, :desc => "Add yourself as auditor", :default => false
|
17
|
+
def create_space
|
18
|
+
space = client.space
|
19
|
+
space.organization = input[:organization]
|
20
|
+
space.name = input[:name]
|
21
|
+
|
22
|
+
with_progress("Creating space #{c(space.name, :name)}") do
|
23
|
+
space.create!
|
24
|
+
end
|
25
|
+
|
26
|
+
if input[:manager]
|
27
|
+
with_progress("Adding you as a manager") do
|
28
|
+
space.add_manager client.current_user
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if input[:developer]
|
33
|
+
with_progress("Adding you as a developer") do
|
34
|
+
space.add_developer client.current_user
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if input[:auditor]
|
39
|
+
with_progress("Adding you as an auditor") do
|
40
|
+
space.add_auditor client.current_user
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if input[:target]
|
45
|
+
invoke :target, :organization => space.organization,
|
46
|
+
:space => space
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def ask_name
|
53
|
+
ask("Name")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "vmc/cli/space/base"
|
2
|
+
|
3
|
+
module VMC::Space
|
4
|
+
class Delete < Base
|
5
|
+
desc "Delete a space and its contents"
|
6
|
+
group :spaces, :hidden => true
|
7
|
+
input :organization, :desc => "Space's organization",
|
8
|
+
:aliases => ["--org", "-o"], :from_given => by_name(:organization),
|
9
|
+
:default => proc { client.current_organization }
|
10
|
+
input :spaces, :desc => "Spaces to delete", :argument => :splat,
|
11
|
+
:singular => :space, :from_given => space_by_name
|
12
|
+
input :recursive, :desc => "Delete recursively", :alias => "-r",
|
13
|
+
:default => false, :forget => true
|
14
|
+
input :warn, :desc => "Show warning if it was the last space",
|
15
|
+
:default => true
|
16
|
+
input :really, :type => :boolean, :forget => true, :hidden => true,
|
17
|
+
:default => proc { force? || interact }
|
18
|
+
def delete_space
|
19
|
+
org = input[:organization]
|
20
|
+
spaces = input[:spaces, org]
|
21
|
+
|
22
|
+
deleted_current = false
|
23
|
+
|
24
|
+
spaces.each do |space|
|
25
|
+
next unless input[:really, space]
|
26
|
+
|
27
|
+
next unless clear_space(space)
|
28
|
+
|
29
|
+
deleted_current ||= space == client.current_space
|
30
|
+
|
31
|
+
with_progress("Deleting space #{c(space.name, :name)}") do
|
32
|
+
space.delete!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
org.invalidate!
|
37
|
+
|
38
|
+
if org.spaces.empty?
|
39
|
+
return unless input[:warn]
|
40
|
+
|
41
|
+
line
|
42
|
+
line c("There are no longer any spaces in #{b(org.name)}.", :warning)
|
43
|
+
line "You may want to create one with #{c("create-space", :good)}."
|
44
|
+
elsif deleted_current
|
45
|
+
invalidate_client
|
46
|
+
invoke :target, :organization => client.current_organization
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def clear_space(space)
|
51
|
+
apps = space.apps
|
52
|
+
services = space.service_instances
|
53
|
+
|
54
|
+
return true if apps.empty? && services.empty?
|
55
|
+
|
56
|
+
unless force?
|
57
|
+
line "This space is not empty!"
|
58
|
+
line
|
59
|
+
line "apps: #{name_list(apps)}"
|
60
|
+
line "service: #{name_list(services)}"
|
61
|
+
line
|
62
|
+
|
63
|
+
return unless input[:recursive]
|
64
|
+
end
|
65
|
+
|
66
|
+
apps.each do |a|
|
67
|
+
invoke :delete, :app => a, :really => true
|
68
|
+
end
|
69
|
+
|
70
|
+
services.each do |i|
|
71
|
+
invoke :delete_service, :service => i, :really => true
|
72
|
+
end
|
73
|
+
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def ask_spaces(org)
|
80
|
+
spaces = org.spaces
|
81
|
+
fail "No spaces." if spaces.empty?
|
82
|
+
|
83
|
+
[ask("Which space in #{c(org.name, :name)}?", :choices => spaces,
|
84
|
+
:display => proc(&:name))]
|
85
|
+
end
|
86
|
+
|
87
|
+
def ask_really(space)
|
88
|
+
ask("Really delete #{c(space.name, :name)}?", :default => false)
|
89
|
+
end
|
90
|
+
|
91
|
+
def ask_recursive
|
92
|
+
ask "Delete #{c("EVERYTHING", :bad)}?", :default => false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|