Class: Kumogata::ArgumentParser
- Inherits:
-
Object
- Object
- Kumogata::ArgumentParser
- Defined in:
- lib/kumogata/argument_parser.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :delete_stack => true, :result_log => File.join(Dir.pwd, 'result.json'), :command_result_log => File.join(Dir.pwd, 'command_result.json'), :color => $stdout.tty?, :debug => false, :config_path => File.('~/.aws/config'), }
- COMMANDS =
{ :create => { :description => 'Create resources as specified in the template', :arguments => [:path_or_url, :stack_name?], :output => false, }, :validate => { :description => 'Validate a specified template', :arguments => [:path_or_url], :output => false, }, :convert => { :description => 'Convert a template format', :arguments => [:path_or_url], }, :update => { :description => 'Update a stack as specified in the template', :arguments => [:path_or_url, :stack_name], :output => false, }, :delete => { :description => 'Delete a specified stack', :arguments => [:stack_name], :output => false, }, :list => { :description => 'List summary information for stacks', :arguments => [:stack_name?], }, :export => { :description => 'Export a template from a specified stack', :arguments => [:stack_name], }, :'show-events' => { :description => 'Show events for a specified stack', :arguments => [:stack_name], }, :'show-outputs' => { :description => 'Show outputs for a specified stack', :arguments => [:stack_name], }, :'show-resources' => { :description => 'Show resources for a specified stack', :arguments => [:stack_name], }, :diff => { :description => 'Compare templates logically (file, http://..., stack://...)', :arguments => [:path_or_url1, :path_or_url2], }, }
Class Method Summary collapse
Instance Method Summary collapse
-
#parse! ⇒ Object
of class methods.
Class Method Details
.parse!(&block) ⇒ Object
66 67 68 |
# File 'lib/kumogata/argument_parser.rb', line 66 def parse!(&block) self.new.parse!(&block) end |
Instance Method Details
#parse! ⇒ Object
of class methods
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/kumogata/argument_parser.rb', line 71 def parse! command = nil arguments = nil = {} if ENV['KUMOGATA_OPTIONS'] ARGV.concat(scan_args(ENV['KUMOGATA_OPTIONS'])) end ARGV. do |opt| update_usage(opt) begin supported_formats = [:ruby, :json, :yaml, :js, :coffee, :json5] opt.on('-k', '--access-key ACCESS_KEY') {|v| [:access_key_id] = v } opt.on('-s', '--secret-key SECRET_KEY') {|v| [:secret_access_key] = v } opt.on('-r', '--region REGION') {|v| [:region] = v } opt.on('' , '--profile CONFIG_PROFILE') {|v| [:config_profile] = v } opt.on('' , '--credentials-path PATH') {|v| [:credentials_path] = v } opt.on('' , '--config-path PATH') {|v| [:config_path] = v } opt.on('' , '--stack-policy-body PATH') {|v| [:stack_policy_body] = File.read(v) } opt.on('' , '--stack-policy-url URL') {|v| [:stack_policy_url] = v } opt.on('' , '--format TMPLATE_FORMAT', supported_formats) {|v| [:format] = v } opt.on('' , '--output-format FORMAT', supported_formats) {|v| [:output_format] = v } opt.on('' , '--skip-replace-underscore') { [:skip_replace_underscore] = false } opt.on('' , '--deletion-policy-retain') { [:deletion_policy_retain] = true } opt.on('-p', '--parameters KEY_VALUES', Array) {|v| [:parameters] = v } opt.on('-j', '--json-parameters JSON') {|v| [:json_parameters] = v } opt.on('-e', '--encrypt-parameters KEYS', Array) {|v| [:encrypt_parameters] = v } opt.on('', '--encryption-password PASS') {|v| [:encryption_password] = v } opt.on('', '--skip-send-password') { [:skip_send_password] = true } opt.on('' , '--capabilities CAPABILITIES', Array) {|v| [:capabilities] = v } opt.on('' , '--disable-rollback') { [:disable_rollback] = true } opt.on('' , '--notify SNS_TOPICS', Array) {|v| [:notify] = v } opt.on('' , '--timeout MINUTES', Integer) {|v| [:timeout] = v } opt.on('' , '--result-log PATH') {|v| [:result_log] = v } opt.on('' , '--command-result-log PATH') {|v| [:command] = v } opt.on('' , '--detach') { [:detach] = true } opt.on('' , '--force') { [:force] = true } opt.on('-w', '--ignore-all-space') { [:ignore_all_space] = true } opt.on('' , '--color') { [:color] = true } opt.on('' , '--no-color') { [:color] = false } opt.on('' , '--debug') { [:debug] = true } opt.on('-v', '--verbose') { [:verbose] = true } opt.parse! unless (command = ARGV.shift) puts opt.help exit 1 end command = command.to_sym unless COMMANDS.has_key?(command) raise "Unknown command: #{command}" end arguments = ARGV.dup validate_arguments(command, arguments) = DEFAULT_OPTIONS.merge() = Hashie::Mash.new() if block_given? yield(opt, command, arguments, ) end update_parameters() rescue => e $stderr.puts("#{e.}") raise e if [:debug] exit 1 end end output = COMMANDS[command].fetch(:output, true) command = command.to_s.gsub('-', '_').to_sym $kumogata.command = command $kumogata.arguments = arguments $kumogata. = = $kumogata. # Copy of the reference [command, arguments, , output] end |