Module: Morpheus::Cli::CliCommand
- Included in:
- Accounts, AppTemplates, Apps, Clouds, Deployments, Deploys, Groups, Hosts, InstanceTypes, Instances, KeyPairs, License, LoadBalancers, Roles, SecurityGroupRules, SecurityGroups, Shell, Tasks, Users, VirtualImages, Workflows
- Defined in:
- lib/morpheus/cli/cli_command.rb
Overview
Module to be included by every CLI command so that commands get registered
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
9 10 11 12 13 |
# File 'lib/morpheus/cli/cli_command.rb', line 9 def self.included(klass) Morpheus::Cli::CliRegistry.add(klass) klass.include Morpheus::Cli::PrintHelper klass.extend ClassMethods end |
Instance Method Details
#build_common_options(opts, options, includes = []) ⇒ Object
15 16 17 18 19 20 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 97 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 |
# File 'lib/morpheus/cli/cli_command.rb', line 15 def (opts, , includes=[]) includes = includes.clone while (option_key = includes.shift) do case option_key.to_sym when :account opts.on('-a','--account ACCOUNT', "Account Name") do |val| [:account_name] = val end opts.on('-A','--account-id ID', "Account ID") do |val| [:account_id] = val end when :options opts.on( '-O', '--option OPTION', "Option" ) do |option| custom_option_args = option.split('=') = [:options] || {} option_name_args = custom_option_args[0].split('.') if option_name_args.count > 1 = option_name_args.each_with_index do |name_element,index| if index < option_name_args.count - 1 [name_element] = [name_element] || {} = [name_element] else [name_element] = custom_option_args[1] end end else [custom_option_args[0]] = custom_option_args[1] end [:options] = end opts.on('-N','--no-prompt', "Skip prompts. Use default values for all optional fields.") do |val| [:no_prompt] = true # ew, stored in here for now because options[:options] is what is passed into OptionTypes.prompt() everywhere! [:options] ||= {} [:options][:no_prompt] = true end when :list opts.on( '-m', '--max MAX', "Max Results" ) do |max| [:max] = max.to_i end opts.on( '-o', '--offset OFFSET', "Offset Results" ) do |offset| [:offset] = offset.to_i end opts.on( '-s', '--search PHRASE', "Search Phrase" ) do |phrase| [:phrase] = phrase end opts.on( '-S', '--sort ORDER', "Sort Order" ) do |v| [:sort] = v end opts.on( '-D', '--desc', "Reverse Sort Order" ) do |v| [:direction] = "desc" end when :remote opts.on( '-r', '--remote REMOTE', "Remote Appliance" ) do |remote| [:remote] = remote end opts.on( '-U', '--url REMOTE', "API Url" ) do |remote| [:remote_url] = remote end opts.on( '-u', '--username USERNAME', "Username" ) do |remote| [:remote_username] = remote end opts.on( '-p', '--password PASSWORD', "Password" ) do |remote| [:remote_password] = remote end opts.on( '-T', '--token ACCESS_TOKEN', "Access Token" ) do |remote| [:remote_token] = remote end when :auto_confirm opts.on( '-y', '--yes', "Auto Confirm" ) do [:yes] = true end when :json opts.on('-j','--json', "JSON Output") do |json| [:json] = true end else raise "Unknown common_option key: #{option_key}" end end # options that are always included opts.on('-C','--nocolor', "ANSI") do Term::ANSIColor::coloring = false end opts.on('-h', '--help', "Prints this help" ) do puts opts exit end end |