# File lib/mcollective/rpc.rb, line 60
    def rpcclient(agent, flags = {})
      configfile = flags[:configfile] || Util.config_file_for_user
      options = flags[:options] || nil

      if flags.key?(:exit_on_failure)
        exit_on_failure = flags[:exit_on_failure]
      else
        # We exit on failure by default for CLI-friendliness
        exit_on_failure = true
      end

      begin
        if options
          rpc = Client.new(agent, :configfile => options[:config], :options => options)
          @options = rpc.options
        else
          rpc = Client.new(agent, :configfile => configfile)
          @options = rpc.options
        end
      rescue Exception => e
        if exit_on_failure
          puts("Could not create RPC client: #{e}")
          exit!
        else
          raise e
        end
      end

      if block_given?
        yield(rpc)
      else
        return rpc
      end
    end