Class: VMC::Organization
- Inherits:
-
CLI
- Object
- Mothership
- CLI
- VMC::Organization
show all
- Defined in:
- lib/vmc/cli/organization.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/organization.rb', line 12
def self.by_name(what, obj = what)
proc { |name, *_|
client.send(:"#{obj}_by_name", name) ||
fail("Unknown #{what} '#{name}'")
}
end
|
Instance Method Details
#create_org ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/vmc/cli/organization.rb', line 101
def create_org
org = client.organization
org.name = input[:name]
org.users = [client.current_user] if input[:add_self]
with_progress("Creating organization #{c(org.name, :name)}") do
org.create!
end
if input[:target]
invoke :target, :organization => org
end
end
|
#delete_org ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
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
|
# File 'lib/vmc/cli/organization.rb', line 134
def delete_org
orgs = client.organizations
fail "No organizations." if orgs.empty?
org = input[:organization, orgs]
return unless input[:really, org]
spaces = org.spaces
unless spaces.empty?
unless force?
line "This organization is not empty!"
line
line "spaces: #{name_list(spaces)}"
line
return unless input[:recursive]
end
spaces.each do |s|
invoke :delete_space, :space => s, :really => true,
:recursive => true, :warn => false
end
end
is_current = org == client.current_organization
with_progress("Deleting organization #{c(org.name, :name)}") do
org.delete!
end
if orgs.size == 1
return unless input[:warn]
line
line c("There are no longer any organizations.", :warning)
line "You may want to create one with #{c("create-org", :good)}."
elsif is_current
invalidate_target
invoke :target
end
end
|
#org ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/vmc/cli/organization.rb', line 28
def org
org = input[:organization]
unless org
return if quiet?
fail "No current organization."
end
if quiet?
puts org.name
return
end
line "#{c(org.name, :name)}:"
indented do
line "domains: #{name_list(org.domains)}"
if input[:full]
line "spaces:"
spaced(org.spaces(:depth => 2)) do |s|
indented do
invoke :space, :space => s
end
end
else
line "spaces: #{name_list(org.spaces)}"
end
end
end
|
#orgs ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/vmc/cli/organization.rb', line 67
def orgs
orgs =
with_progress("Getting organizations") do
client.organizations
end
line unless quiet?
if input[:one_line]
table(
%w{name spaces domains},
orgs.collect { |o|
[ c(o.name, :name),
name_list(o.spaces),
name_list(o.domains)
]
})
else
orgs.each do |o|
invoke :org, :organization => o, :full => input[:full]
end
end
end
|
#precondition ⇒ Object
5
6
7
8
9
10
|
# File 'lib/vmc/cli/organization.rb', line 5
def precondition
check_target
check_logged_in
fail "This command is v2-only." unless v2?
end
|