lib/relish/commands/base.rb in relish-0.1.0 vs lib/relish/commands/base.rb in relish-0.1.1
- old
+ new
@@ -1,26 +1,28 @@
require 'yaml'
require 'json'
require 'relish/ui'
+require 'relish/helpers'
require 'relish/options_file'
require 'relish/commands/dsl'
+require 'relish/commands/param_methods'
module Relish
module Command
class Base
+ include Relish::Helpers
extend Dsl
- option :project
option :api_token, :default => lambda { get_and_store_api_token }
option :host, :default => lambda { Relish.default_host }, :display => false
attr_writer :args
attr_reader :cli_options
def initialize(args = [])
@args = clean_args(args)
- @param = get_param
+ @param = get_param.extend(ParamMethods)
@cli_options = Hash[*@args]
validate_cli_options
end
@@ -31,10 +33,14 @@
def get_param
@args.shift if @args.size.odd?
end
private
+
+ def project
+ merged_options['project'] || error('You must specify a project.')
+ end
def get_and_store_api_token
api_token = get_api_token
global_options_file.store('api_token' => api_token)
api_token
@@ -60,15 +66,18 @@
def valid_option_names
Dsl::Option.names
end
def validate_cli_options
- @cli_options.keys.each do |option|
+ cli_options.keys.each do |option|
unless valid_option_names.include?(option.to_s)
- puts "#{option} is not a valid option."
- exit 1
+ error "'#{option}' is not a valid option."
end
end
+ end
+
+ def merged_options
+ @merged_options ||= global_options_file.merge(local_options_file)
end
def global_options_file
@global_options ||= OptionsFile.new(Relish.global_options_file)
end
\ No newline at end of file