Class: Morpheus::Cli::Options
- Inherits:
-
Object
- Object
- Morpheus::Cli::Options
show all
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/commands/options.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
Methods included from CliCommand
#apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Instance Method Details
#connect(opts) ⇒ Object
12
13
14
15
|
# File 'lib/morpheus/cli/commands/options.rb', line 12
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@options_interface = @api_client.options
end
|
#handle(args) ⇒ Object
17
18
19
|
# File 'lib/morpheus/cli/commands/options.rb', line 17
def handle(args)
list(args)
end
|
#list(args) ⇒ Object
21
22
23
24
25
26
27
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
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
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/morpheus/cli/commands/options.rb', line 21
def list(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = "Usage: morpheus #{command_name} [source] [option-type]"
build_standard_get_options(opts, options)
opts. = <<-EOT
View options by source name or list options for a specific library option type.
[source] is required. This is the name of the options source to load eg. "currencies"
[option-type] is required when [source] is 'list'. This is the name or id of an option type to view.
Examples:
options currencies
options dnsRecordType
options list "widgets"
EOT
end
optparse.parse!(args)
source_name = args[0]
option_type_id = args.size > 1 ? args[1..-1].join(" ") : nil
if source_name == "list"
verify_args!(args:args, optparse:optparse, min: 2)
else
verify_args!(args:args, optparse:optparse, count: 1)
end
connect(options)
params.merge!(parse_list_options(options))
if source_name == "list"
if option_type_id.to_s =~ /\A\d{1,}\Z/
params["optionTypeId"] = option_type_id
else
option_type = find_by_name_or_id(:option_type, option_type_id)
if option_type.nil?
return 1, "Option Type not found by name '#{option_type_id}'"
end
params["optionTypeId"] = option_type["id"]
end
end
@options_interface.setopts(options)
if options[:dry_run]
print_dry_run @options_interface.dry.options_for_source(source_name, params)
return
end
json_response = nil
begin
json_response = @options_interface.options_for_source(source_name, params)
rescue RestClient::Exception => e
if e.response && e.response.code == 404
raise_command_error("Options source not found by name '#{source_name}'", args, optparse)
elsif e.response && e.response.code == 500
if e.response.body.to_s.include?("groovy.lang.MissingMethodException")
raise_command_error("Options source not found by name '#{source_name}'", args, optparse)
else
raise e
end
else
raise e
end
end
render_response(json_response, options, "data") do
records = json_response["data"]
print_h1 "Morpheus Options", ["Source: #{source_name}"] + parse_list_subtitles(options), options
if records.nil? || records.empty?
print cyan,"No options found.",reset,"\n"
else
print as_pretty_table(records, [:name, :value], options)
(json_response)
end
print reset,"\n"
end
return 0, nil
end
|