Module: Facter::Application

### Home Classes Methods

### In Files

- lib/facter/application.rb

### Methods

- ::create_directory_loader
- ::create_nothing_loader
- ::run

### Files

- LICENSE
- Rakefile
- THANKS

### Class/Module Index

Quicksearch

- Facter
- Facter::Application
- Facter::Manufacturer
- Facter::Memory
- Facter::NetMask
- Facter::Util
- Facter::Util::CFPropertyList
- Facter::Util::CFPropertyList::CFArray
- Facter::Util::CFPropertyList::CFBoolean
- Facter::Util::CFPropertyList::CFData
- Facter::Util::CFPropertyList::CFDate
- Facter::Util::CFPropertyList::CFDictionary
- Facter::Util::CFPropertyList::CFInteger
- Facter::Util::CFPropertyList::CFReal
- Facter::Util::CFPropertyList::CFString
- Facter::Util::CFPropertyList::CFType
- Facter::Util::CFPropertyList::XML
- Facter::Util::Collection
- Facter::Util::CompositeLoader
- Facter::Util::Config
- Facter::Util::Confine
- Facter::Util::DirectoryLoader
- Facter::Util::DirectoryLoader::NoSuchDirectoryError
- Facter::Util::EC2
- Facter::Util::Fact
- Facter::Util::FileRead
- Facter::Util::IP
- Facter::Util::IP::Windows
- Facter::Util::IP::Windows::Bindings4
- Facter::Util::IP::Windows::Bindings6
- Facter::Util::Loader
- Facter::Util::Macaddress
- Facter::Util::Macaddress::Darwin
- Facter::Util::Macaddress::Windows
- Facter::Util::Macosx
- Facter::Util::MonkeyPatches
- Facter::Util::MonkeyPatches::Lines
- Facter::Util::NothingLoader
- Facter::Util::Parser
- Facter::Util::Parser::Base
- Facter::Util::Parser::JsonParser
- Facter::Util::Parser::KeyValuePairOutputFormat
- Facter::Util::Parser::NothingParser
- Facter::Util::Parser::PowershellParser
- Facter::Util::Parser::ScriptParser
- Facter::Util::Parser::TextParser
- Facter::Util::Parser::YamlParser
- Facter::Util::Processor
- Facter::Util::Registry
- Facter::Util::Resolution
- Facter::Util::SolarisZones
- Facter::Util::Uptime
- Facter::Util::Values
- Facter::Util::Virtual
- Facter::Util::Vlans
- Facter::Util::WMI
- Facter::Util::Xendomains
- Plist
- Plist::Emit
- Plist::Listener
- Plist::PArray
- Plist::PData
- Plist::PDate
- Plist::PDict
- Plist::PFalse
- Plist::PInteger
- Plist::PKey
- Plist::PList
- Plist::PReal
- Plist::PString
- Plist::PTag
- Plist::PTrue
- Plist::StreamParser
- CFFormatError
- CFPlistError
- CFTypeError
- IO
- Object
- String

No matching classes.

# Facter::Application

### Public Class Methods

create_directory_loader(dir) click to toggle source

    # File lib/facter/application.rb, line 6
    def self.create_directory_loader(dir)
      begin
        Facter::Util::Config.ext_fact_loader = Facter::Util::DirectoryLoader.loader_for(dir)
      rescue Facter::Util::DirectoryLoader::NoSuchDirectoryError => error
        $stderr.puts "Specified external facts directory #{dir} does not exist."
        exit(1)
      end
    end

create_nothing_loader() click to toggle source

    # File lib/facter/application.rb, line 15
    def self.create_nothing_loader
      Facter::Util::Config.ext_fact_loader = Facter::Util::NothingLoader.new
    end

run(argv) click to toggle source

    # File lib/facter/application.rb, line 19
    def self.run(argv)
      require 'optparse'
      require 'facter'

      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
            $stderr.puts "Could not retrieve #{name}: #{error}"
            exit 10
          end
        end
      end

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

      # Print the facts as YAML and exit
      if options[:yaml]
        require 'yaml'
        puts YAML.dump(facts)
        exit(0)
      end

      # Print the facts as JSON and exit
      if options[:json]
        begin
          require 'json'
          puts JSON.dump(facts)
          exit(0)
        rescue LoadError
          $stderr.puts "You do not have JSON support in your version of Ruby. JSON output disabled"
          exit(1)
        end
      end

      # Print the value of a single fact, otherwise print a list sorted by fact
      # name and separated by "=>"
      if facts.length == 1
        if value = facts.values.first
          puts value
        end
      else
        facts.sort_by{ |fact| fact.first }.each do |name,value|
          puts "#{name} => #{value}"
        end
      end

    rescue => e
      if options && options[:trace]
        raise e
      else
        $stderr.puts "Error: #{e}"
        exit(12)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.