diff options
author | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-09-19 06:55:52 +0000 |
---|---|---|
committer | luke <luke@1f5c1d6a-bddf-0310-8f58-fc49e503516a> | 2006-09-19 06:55:52 +0000 |
commit | fe0f2f204fdd5d4c48af93d691cce53061cd1ded (patch) | |
tree | 68acc999c6e42c6f0eda9afa00c81886c5425ba4 | |
parent | 4abbce9119f91179aaa7aeb2f92466cc201a9079 (diff) | |
download | facter-fe0f2f204fdd5d4c48af93d691cce53061cd1ded.tar.gz facter-fe0f2f204fdd5d4c48af93d691cce53061cd1ded.tar.xz facter-fe0f2f204fdd5d4c48af93d691cce53061cd1ded.zip |
Adding yaml support, as requested in #24
git-svn-id: http://reductivelabs.com/svn/facter/trunk@170 1f5c1d6a-bddf-0310-8f58-fc49e503516a
-rwxr-xr-x | bin/facter | 13 | ||||
-rwxr-xr-x | tests/tc_facterbin.rb | 18 |
2 files changed, 31 insertions, 0 deletions
@@ -59,14 +59,21 @@ result = GetoptLong.new( [ "--version", "-v", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], + [ "--yaml", "-y", GetoptLong::NO_ARGUMENT ], [ "--config", "-c", GetoptLong::REQUIRED_ARGUMENT ] ) +options = { + :yaml => false +} + result.each { |opt,arg| case opt when "--version" puts "%s" % Facter.version exit + when "--yaml" + options[:yaml] = true when "--debug" Facter.debugging(1) when "--help" @@ -113,6 +120,12 @@ else } end +if options[:yaml] + require 'yaml' + puts YAML.dump(facts) + exit(0) +end + facts.sort { |a, b| a[0].to_s <=> b[0].to_s }.each { |name,value| if facts.length == 1 unless value.nil? diff --git a/tests/tc_facterbin.rb b/tests/tc_facterbin.rb index b2b8100..9d9ca15 100755 --- a/tests/tc_facterbin.rb +++ b/tests/tc_facterbin.rb @@ -60,6 +60,24 @@ class TestFacterBin < Test::Unit::TestCase assert(output !~ / => /, "Output includes the farrow thing") end + + def test_yaml + out = nil + assert_nothing_raised { + out = %x{facter -y} + } + + require 'yaml' + result = nil + assert_nothing_raised { + result = YAML.load(out) + } + + assert_instance_of(Hash, result) + result.each do |name, value| + assert_equal(value, Facter.value(name)) + end + end end # $Id$ |