# File lib/facter/application.rb, line 23
    def self.run(argv)
      options = parse(argv)

      # Accept fact names to return from the command line
      names = argv

      # Change location of external facts dir
      # Check here for valid ext_dir and exit program

      # Create the facts hash that is printed to standard out.
      unless names.empty?
        facts = {}
        names.each do |name|
          begin
            facts[name] = Facter.value(name)
          rescue => error
            Facter.log_exception(error, "Could not retrieve #{name}: #{error.message}")
            exit(10)
          end
        end
      end

      # Print everything if they didn't ask for specific facts.
      facts ||= Facter.to_hash

      output = nil

      if options[:yaml]
        output = Facter::Util::Formatter.format_yaml(facts)
      elsif options[:json]
        output = Facter::Util::Formatter.format_json(facts)
      elsif options[:plaintext]
        output = Facter::Util::Formatter.format_plaintext(facts)
      else
        output = Facter::Util::Formatter.format_plaintext(facts)
      end

      puts output
      exit(0)

    rescue => e
      Facter.log_exception(e)
      exit(12)
    end