# File lib/chef/knife.rb, line 240
    def configure_chef
      unless config[:config_file]
        full_path = Dir.pwd.split(File::SEPARATOR)
        (full_path.length - 1).downto(0) do |i|
          config_file_to_check = File.join([ full_path[0..i], ".chef", "knife.rb" ].flatten)
          if File.exists?(config_file_to_check)
            config[:config_file] = config_file_to_check 
            break
          end
        end
        # If we haven't set a config yet and $HOME is set, and the home
        # knife.rb exists, use it:
        if (!config[:config_file]) && ENV['HOME'] && File.exist?(File.join(ENV['HOME'], '.chef', 'knife.rb'))
          config[:config_file] = File.join(ENV['HOME'], '.chef', 'knife.rb')
        end
      end

      # Don't try to load a knife.rb if it doesn't exist.
      if config[:config_file]
        Chef::Config.from_file(config[:config_file])
      else
        # ...but do log a message if no config was found.
        self.msg("No knife configuration file found")
      end

      Chef::Config[:log_level] = config[:log_level] if config[:log_level]
      Chef::Config[:log_location] = config[:log_location] if config[:log_location]
      Chef::Config[:node_name] = config[:node_name] if config[:node_name]
      Chef::Config[:client_key] = config[:client_key] if config[:client_key]
      Chef::Config[:chef_server_url] = config[:chef_server_url] if config[:chef_server_url]
      Chef::Log.init(Chef::Config[:log_location])
      Chef::Log.level(Chef::Config[:log_level])

      Chef::Log.debug("Using configuration from #{config[:config_file]}")

      if Chef::Config[:node_name].nil?
        raise ArgumentError, "No user specified, pass via -u or specifiy 'node_name' in #{config[:config_file] ? config[:config_file] : "~/.chef/knife.rb"}"
      end
    end