Module: Facter::Application
- Defined in:
- lib/facter/application.rb
Class Method Summary collapse
Class Method Details
.create_directory_loader(dir) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/facter/application.rb', line 10 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 Facter.log_exception(error, "Specified external facts directory #{dir} does not exist.") exit(1) end end |
.create_nothing_loader ⇒ Object
19 20 21 |
# File 'lib/facter/application.rb', line 19 def self.create_nothing_loader Facter::Util::Config.ext_fact_loader = Facter::Util::NothingLoader.new end |
.run(argv) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/facter/application.rb', line 23 def self.run(argv) = 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.}") exit(10) end end end # Print everything if they didn't ask for specific facts. facts ||= Facter.to_hash output = nil if [:yaml] output = Facter::Util::Formatter.format_yaml(facts) elsif [:json] output = Facter::Util::Formatter.format_json(facts) elsif [: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 |