Class: VMC::Space
- Inherits:
-
CLI
- Object
- Mothership
- CLI
- VMC::Space
show all
- Defined in:
- lib/vmc/cli/space.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CLI
#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #default_action, #ensure_config_dir, #err, #execute, #fail, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #one_of, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?
Methods included from Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Class Method Details
.by_name(what, obj = what) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/vmc/cli/space.rb', line 12
def self.by_name(what, obj = what)
proc { |name, *_|
client.send(:"#{obj}_by_name", name) ||
fail("Unknown #{what} '#{name}'")
}
end
|
.space_by_name ⇒ Object
19
20
21
22
23
24
|
# File 'lib/vmc/cli/space.rb', line 19
def self.space_by_name
proc { |name, org, *_|
org.space_by_name(name) ||
fail("Unknown space '#{name}'")
}
end
|
Instance Method Details
#create_space ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/vmc/cli/space.rb', line 145
def create_space
space = client.space
space.organization = input[:organization]
space.name = input[:name]
with_progress("Creating space #{c(space.name, :name)}") do
space.create!
end
if input[:manager]
with_progress("Adding you as a manager") do
space.add_manager client.current_user
end
end
if input[:developer]
with_progress("Adding you as a developer") do
space.add_developer client.current_user
end
end
if input[:auditor]
with_progress("Adding you as an auditor") do
space.add_auditor client.current_user
end
end
if input[:target]
invoke :target, :organization => space.organization,
:space => space
end
end
|
#delete_space ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/vmc/cli/space.rb', line 215
def delete_space
org = input[:organization]
spaces = input[:spaces, org]
deleted_current = false
spaces.each do |space|
next unless input[:really, space]
next unless clear_space(space)
deleted_current ||= space == client.current_space
with_progress("Deleting space #{c(space.name, :name)}") do
space.delete!
end
end
org.invalidate!
if org.spaces.empty?
return unless input[:warn]
line
line c("There are no longer any spaces in #{b(org.name)}.", :warning)
line "You may want to create one with #{c("create-space", :good)}."
elsif deleted_current
invalidate_client
invoke :target, :organization => client.current_organization
end
end
|
#precondition ⇒ Object
5
6
7
8
9
10
|
# File 'lib/vmc/cli/space.rb', line 5
def precondition
check_target
check_logged_in
fail "This command is v2-only." unless v2?
end
|
#space ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/vmc/cli/space.rb', line 38
def space
org = input[:organization]
space = input[:space, org]
unless space
return if quiet?
fail "No current space."
end
if quiet?
puts space.name
return
end
line "#{c(space.name, :name)}:"
indented do
line "organization: #{c(space.organization.name, :name)}"
if input[:full]
line
line "apps:"
spaced(space.apps(:depth => 2)) do |a|
indented do
invoke :app, :app => a
end
end
else
line "apps: #{name_list(space.apps)}"
end
if input[:full]
line
line "services:"
spaced(space.service_instances(:depth => 2)) do |i|
indented do
invoke :service, :instance => i
end
end
else
line "services: #{name_list(space.service_instances)}"
end
line "domains: #{name_list(space.domains)}"
end
end
|
#spaces ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/vmc/cli/space.rb', line 98
def spaces
org = input[:organization]
spaces =
with_progress("Getting spaces in #{c(org.name, :name)}") do
org.spaces
end
line unless quiet?
spaces.reject! do |s|
!space_matches(s, input)
end
if input[:one_line]
table(
%w{name apps services},
spaces.collect { |s|
[ c(s.name, :name),
name_list(s.apps),
name_list(s.service_instances)
]
})
else
spaced(spaces) do |s|
invoke :space, :space => s, :full => input[:full]
end
end
end
|
#take_space ⇒ Object
182
183
184
185
186
187
188
|
# File 'lib/vmc/cli/space.rb', line 182
def take_space
if space = client.space_by_name(input[:name])
invoke :target, :space => space
else
invoke :create_space, :name => input[:name], :target => true
end
end
|