# File lib/rhc/commands.rb, line 22
    def parse_options_and_call_procs *args
      runner = Commander::Runner.instance
      opts = OptionParser.new

      # add global options
      runner.options.each do |option|
        opts.on(*option[:args], &runner.global_option_proc(option[:switches], &option[:proc]))
      end

      # add command options
      @options.each do |option|
        opts.on(*option[:args], &option[:proc])
        opts
      end

      # Separate option lists with '--'
      remaining = args.split('--').map{ |a| opts.parse!(a) }.inject([]) do |arr, sub|
        arr << '--' unless arr.empty?
        arr.concat(sub)
      end

      _, config_path = proxy_options.find{ |arg| arg[0] == :config }
      clean, _ = proxy_options.find{ |arg| arg[0] == :clean }

      begin
        @config = RHC::Config.new
        @config.use_config(config_path) if config_path
        $terminal.debug("Using config file #{@config.config_path}")

        unless clean
          @config.to_options.each_pair do |key, value|
            next if proxy_options.detect{ |arr| arr[0] == key }
            if sw = opts.send(:search, :long, key.to_s.gsub(/_/, '-'))
              _, cb, val = sw.send(:conv_arg, nil, value) {|*exc| raise(*exc) }
              cb.call(val) if cb
            else
              proxy_options << [key, value]
            end
          end
        end
      rescue ArgumentError => e
        n = OptionParser::InvalidOption.new(e.message)
        n.reason = "The configuration file #{@config.path} contains an invalid setting"
        n.set_backtrace(e.backtrace)
        raise n
      rescue OptionParser::ParseError => e
        e.reason = "The configuration file #{@config.path} contains an invalid setting"
        raise
      end
      remaining
    end