summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn E. Vincent <lusis.org+github.com@gmail.com>2010-11-04 00:07:06 -0400
committerJohn E. Vincent <lusis.org+github.com@gmail.com>2010-11-04 00:07:06 -0400
commit1fa87a9c1ed9f9a841936615d27c61dc1d2d7fce (patch)
treee73347000ef7b70c93e67f25cd83a1bfefdb0f03 /lib
parent7e35d98964b3534281b3d1f164e548a86fce18dd (diff)
downloadfacter-1fa87a9c1ed9f9a841936615d27c61dc1d2d7fce.tar.gz
facter-1fa87a9c1ed9f9a841936615d27c61dc1d2d7fce.tar.xz
facter-1fa87a9c1ed9f9a841936615d27c61dc1d2d7fce.zip
JSON support. Works in 1.9.1. Warnings in 1.9.2. LoadError on 1.8.7 for some reason
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/application.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/facter/application.rb b/lib/facter/application.rb
index 9de9249..9d6bc34 100644
--- a/lib/facter/application.rb
+++ b/lib/facter/application.rb
@@ -31,6 +31,18 @@ module Facter
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
@@ -58,6 +70,7 @@ module Facter
options = {}
OptionParser.new do |opts|
opts.on("-y", "--yaml") { |v| options[:yaml] = v }
+ opts.on("-j", "--json") { |v| options[:json] = v }
opts.on( "--trace") { |v| options[:trace] = v }
opts.on("-d", "--debug") { |v| Facter.debugging(1) }
opts.on("-t", "--timing") { |v| Facter.timing(1) }