lib/heirloom/cli/shared.rb in heirloom-0.4.1rc1 vs lib/heirloom/cli/shared.rb in heirloom-0.5.0rc1
- old
+ new
@@ -1,14 +1,27 @@
module Heirloom
module CLI
module Shared
- def valid_options?(args)
+ def load_config(args)
+ opts = args[:opts]
+ logger = args[:logger]
+ config = Config.new :logger => logger
+ config.access_key = opts[:key] if opts[:key_given]
+ config.secret_key = opts[:secret] if opts[:secret_given]
+ config
+ end
+
+ def ensure_valid_options(args)
provided = args[:provided]
required = args[:required]
- logger = args[:logger]
+ config = args[:config]
+ logger = config.logger
+ required << :key unless config.access_key
+ required << :secret unless config.secret_key
+
missing_opts = required.map do |opt|
case provided[opt]
when nil
"Option '#{opt} (-#{opt[0]})' required but not specified."
when []
@@ -18,19 +31,10 @@
missing_opts.compact!
missing_opts.each {|missing_opt| logger.error missing_opt}
- missing_opts.empty?
- end
-
- def load_config(args)
- opts = args[:opts]
- logger = args[:logger]
- config = Config.new :logger => logger
- config.access_key = opts[:key] if opts[:key_given]
- config.secret_key = opts[:secret] if opts[:secret_given]
- config
+ exit 1 unless missing_opts.empty?
end
def ensure_domain_exists(args)
config = args[:config]
name = args[:name]