# File lib/rhc/commands.rb, line 244
      def self.fill_arguments(cmd, options, args_metadata, options_metadata, args)
        Commander::Runner.instance.options.each do |opt|
          if opt[:context]
            arg = Commander::Runner.switch_to_sym(opt[:switches].last)
            options.__hash__[arg] ||= lambda{ cmd.send(opt[:context]) }
          end
        end

        # 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(", ") }
            RHC::Helpers.deprecated_option(incorrect, correct)
          end

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

        available = args.dup
        slots = Array.new(args_metadata.length)
        args_metadata.each_with_index do |arg, i|
          option = arg[:option_symbol]
          context_helper = arg[:context_helper]

          value = options.__hash__[option] if option

          if value.nil?
            value =
              if arg[:arg_type] == :list
                all = []
                while available.first && available.first != '--'
                  all << available.shift
                end
                available.shift if available.first == '--'
                all
              else
                available.shift
              end
          end

          value = cmd.send(context_helper) if value.nil? and context_helper

          if value.nil?
            raise ArgumentError, "Missing required argument '#{arg[:name]}'." unless arg[:optional]
            break if available.empty?
          else
            value = Array(value) if arg[:arg_type] == :list
            slots[i] = value
            options.__hash__[option] = value if option
          end
        end

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

        slots
      end