lib/redis_failover/cli.rb in redis_failover-0.8.3 vs lib/redis_failover/cli.rb in redis_failover-0.8.4

- old
+ new

@@ -34,23 +34,27 @@ opts.on('--max-failures COUNT', 'Max failures before manager marks node unavailable') do |max| options[:max_failures] = Integer(max) end - opts.on '-C', '--config PATH', "Path to YAML configuration file" do |file| + opts.on('-C', '--config PATH', 'Path to YAML config file') do |file| options[:config_file] = file end + opts.on('-E', '--environment ENV', 'Config environment to use') do |config_env| + options[:config_environment] = config_env + end + opts.on('-h', '--help', 'Display all options') do puts opts exit end end parser.parse(source) if config_file = options[:config_file] - options = from_file(config_file) + options = from_file(config_file, options[:config_environment]) end if required_options_missing?(options) puts parser exit @@ -67,16 +71,24 @@ end # Parses options from a YAML file. # # @param [String] file the filename + # @params [String] env the environment # @return [Hash] the parsed options - def self.from_file(file) + def self.from_file(file, env = nil) unless File.exists?(file) raise ArgumentError, "File #{file} can't be found" end options = YAML.load_file(file) + + if env + options = options.fetch(env.to_sym) do + raise ArgumentError, "Environment #{env} can't be found in config" + end + end + options[:nodes] = options[:nodes].join(',') options[:zkservers] = options[:zkservers].join(',') options end @@ -98,6 +110,6 @@ end options end end -end \ No newline at end of file +end