Please review pull request #35: --format json opened by (mgwilliams)

Description:

Added --format option to select output format (json), e.g.:

$ ./hiera "interfaces" --format json
{"eth0":{"address":"192.168.34.137","mode":"dhcp"}}


    
  • Opened: Thu Feb 23 06:53:59 UTC 2012
  • Based on: puppetlabs:master (4b2ae058e9a60532886158af1ef8d7ce08118653)
  • Requested merge: flowroute:master (d5d797f7108431f440de8e5f009447fbecbdc1ce)

Diff follows:

diff --git a/bin/hiera b/bin/hiera
index cc4c8a8..d1eccff 100755
--- a/bin/hiera
+++ b/bin/hiera
@@ -164,6 +164,16 @@ OptionParser.new do |opts|
       exit 1
     end
   end
+  opts.on("--format FORMAT", "-f", "Specify format for output (currently json or ruby)") do |v|
+    if v == "json" 
+      options[:format] = :json
+    elsif v == "ruby"
+      options[:format] = :ruby
+    else
+      STDERR.puts "Invalid format specified (expected json or ruby)"
+      exit 1
+    end
+  end
 end.parse!
 
 # arguments can be:
@@ -209,6 +219,9 @@ ans = hiera.lookup(options[:key], options[:default], options[:scope], nil, optio
 
 if ans.is_a?(String)
   puts ans
+elsif options[:format] == :json
+  require 'json'
+  puts JSON.generate(ans)
 else
   p ans
 end

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to