# File lib/rhc/commands/base.rb, line 21
  def validate_args_and_options(args_metadata, options_metadata, args)
    # process options
    options_metadata.each do |option_meta|
      arg = option_meta[:arg]

      # Check to see if we've provided a value for an option tagged as deprecated
      if (!(val = @options.__hash__[arg]).nil? && dep_info = option_meta[:deprecated])
        # Get the arg for the correct option and what the value should be
        (correct_arg, default) = dep_info.values_at(:key, :value)
        # Set the default value for the correct option to the passed value
        ## Note: If this isn't triggered, then the original default will be honored
        ## If the user specifies any value for the correct option, it will be used
        options.default correct_arg => default
        # Alert the users if they're using a deprecated option
        (correct, incorrect) = [options_metadata.find{|x| x[:arg] == correct_arg },option_meta].flatten.map{|x| x[:switches].join(", ") }
        deprecated_option(incorrect, correct)
      end

      context_helper = option_meta[:context_helper]

      @options.__hash__[arg] = self.send(context_helper) if @options.__hash__[arg].nil? and context_helper
      raise ArgumentError.new("Missing required option '#{arg}'.") if option_meta[:required] and @options.__hash__[arg].nil?
    end

    # process args
    arg_slots = [].fill(nil, 0, args_metadata.length)
    fill_args = args.reverse
    args_metadata.each_with_index do |arg_meta, i|
      # check options
      value = @options.__hash__[arg_meta[:option_symbol]] unless arg_meta[:option_symbol].nil?
      if value
        arg_slots[i] = value
      elsif arg_meta[:arg_type] == :list
        arg_slots[i] = fill_args.reverse
        fill_args = []
      else
        raise ArgumentError.new("Missing required argument '#{arg_meta[:name]}'.") if fill_args.empty?
        arg_slots[i] = fill_args.pop
      end
    end

    raise ArgumentError.new("Too many arguments passed in: #{fill_args.reverse.join(" ")}") unless fill_args.empty?

    arg_slots
  end