Class: MMS::CLI::Command
- Inherits:
-
Clamp::Command
- Object
- Clamp::Command
- MMS::CLI::Command
show all
- Defined in:
- lib/mms/cli.rb
Defined Under Namespace
Classes: Alerts, Clusters, Groups, Hosts, RestoreJobs, Snapshots
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(invocation_path, context = {}, parent_attribute_values = {}) ⇒ Command
Returns a new instance of Command.
54
55
56
|
# File 'lib/mms/cli.rb', line 54
def initialize(invocation_path, context = {}, parent_attribute_values = {})
@config ||= MMS::Config.new
end
|
Instance Attribute Details
74
75
76
|
# File 'lib/mms/cli.rb', line 74
def agent
@agent
end
|
#app_name ⇒ Object
Returns the value of attribute app_name.
10
11
12
|
# File 'lib/mms/cli.rb', line 10
def app_name
@app_name
end
|
#client ⇒ Object
Returns the value of attribute client.
13
14
15
|
# File 'lib/mms/cli.rb', line 13
def client
@client
end
|
#config ⇒ Object
Returns the value of attribute config.
11
12
13
|
# File 'lib/mms/cli.rb', line 11
def config
@config
end
|
Instance Method Details
86
87
88
89
90
91
92
|
# File 'lib/mms/cli.rb', line 86
def clusters
id = ignore? ? nil : @config.default_cluster_id
groups.collect! do |group|
id.nil? ? group.clusters : group.cluster(id)
end.flatten
end
|
80
81
82
83
|
# File 'lib/mms/cli.rb', line 80
def groups
id = ignore? ? nil : @config.default_group_id
id.nil? ? agent.groups : [agent.find_group(id)]
end
|
#parse_user_home_config ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mms/cli.rb', line 58
def parse_user_home_config
raise(MMS::ConfigError.new('Config file path is not set!')) if @config.config_path.nil?
config_file = Pathname.new(@config.config_path)
raise(MMS::ConfigError.new("Config file `#{config_file}` does not exist")) unless config_file.exist?
config = ParseConfig.new(config_file)
config.params.map do |key, value|
begin
@config.send("#{key}=", value)
rescue Exception => e
raise MMS::ConfigError.new("Config option `#{key}` from file `#{config_file}` is not allowed!")
end
end
end
|
#print(heading, resource_list) ⇒ Object
96
97
98
|
# File 'lib/mms/cli.rb', line 96
def print(heading, resource_list)
json? ? print_json(resource_list) : print_human(heading, resource_list)
end
|
#print_human(heading, resource_list) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/mms/cli.rb', line 102
def print_human(heading, resource_list)
rows = []
resource_list.first(@config.limit).each do |resource|
rows += resource.table_section
end
puts Terminal::Table.new :headings => (heading.nil? ? [] : heading), :rows => rows
print_tips unless ignore?
end
|
#print_json(resource_list) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/mms/cli.rb', line 115
def print_json(resource_list)
rows = []
resource_list.first(@config.limit).each do |resource|
rows.push(resource.to_hash)
end
puts JSON.pretty_generate(rows)
end
|
#print_tips ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/mms/cli.rb', line 125
def print_tips
puts 'Default group: ' + @config.default_group_id unless @config.default_group_id.nil?
puts 'Default cluster: ' + @config.default_cluster_id unless @config.default_cluster_id.nil?
if !@config.default_group_id.nil? or !@config.default_cluster_id.nil?
puts "Add flag --ignore or update --default-group-id, --default-cluster-id or update your `#{@config.config_path}` to see all resources"
end
end
|
#run(arguments) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/mms/cli.rb', line 136
def run(arguments)
begin
parse_user_home_config
super
rescue Clamp::HelpWanted => e
raise(help)
rescue Clamp::UsageError => e
raise([e.message, help].join("\n"))
rescue MMS::AuthError => e
raise('Authorisation problem. Please check you credential!')
rescue MMS::ResourceError => e
raise(["Resource #{e.resource.class.name} problem:", e.message].join("\n"))
end
end
|