lib/ddbcli/cli/options.rb in ddbcli-0.2.1 vs lib/ddbcli/cli/options.rb in ddbcli-0.2.2
- old
+ new
@@ -1,7 +1,8 @@
require 'optparse'
require 'ostruct'
+require 'uri'
def parse_options
options = OpenStruct.new
options.access_key_id = ENV['AWS_ACCESS_KEY_ID']
options.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
@@ -18,9 +19,18 @@
ARGV.options do |opt|
opt.on('-k', '--access-key=ACCESS_KEY') {|v| options.access_key_id = v }
opt.on('-s', '--secret-key=SECRET_KEY') {|v| options.secret_access_key = v }
opt.on('-r', '--region=REGION_OR_ENDPOINT') {|v| options.ddb_endpoint_or_region = v }
+
+ opt.on('', '--uri=URI') {|v|
+ uri = v
+ uri = "http://#{uri}" unless uri =~ %r|\A\w+://|
+ uri = URI.parse(uri)
+ raise URI::InvalidURIError, "invalid shceme: #{v}" unless /\Ahttps?\Z/ =~ uri.scheme
+ options.ddb_endpoint_or_region = uri
+ }
+
opt.on('-e', '--eval=COMMAND') {|v| options.command = v }
opt.on('-t', '--timeout=SECOND', Integer) {|v| options.timeout = v.to_i }
opt.on('', '--import=TABLE,JSON_FILE') {|v|
v = v.split(/\s*,\s*/, 2)