bin/onering in onering-client-0.0.29 vs bin/onering in onering-client-0.0.30

- old
+ new

@@ -148,11 +148,11 @@ unless STDIN.tty? begin json = ::JSON.load(STDIN.read) raise "Input document must specify an ID" if sc[:args].empty? and not json['id'] - print_format(api.save((sc[:args].first || json['id']), json)) + print_format(api.save((sc[:args].first || json['id']), json), :json) rescue Exception => e STDERR.puts "#{e.class.name}: #{e.message}" exit 1 end end @@ -230,34 +230,71 @@ :method => (call[:method] || :get), :data => (STDIN.tty? ? {} : ::JSON.load(STDIN.read)), :fields => (Hash[call[:opts].collect{|i| i.split(':',2) }] rescue {}) }) - print_format(rv, call[:format]) unless rv.nil? or rv.to_s.strip.chomp.empty? + print_format(rv, call[:format] || :json) unless rv.nil? or rv.to_s.strip.chomp.empty? end end subcommand :fact, "Retrieve a system fact" do |fact| fact.usage = "onering fact NAME [DEFAULT] [NAME2 [DEFAULT2] ..]" fact.opt :format, '-t', '--format FORMAT', "Return the results as FORMAT" fact.exec do + Onering::Reporter.setup() rv = [] fact[:args].each_index do |i| if i.even? name = fact[:args][i] else default = fact[:args][i] end - rv << Onering::Util.fact(name, default) + rv << Onering::Reporter.fact(name, default) end rv.compact! rv = rv.first if rv.length == 1 - print_format(rv, fact[:format]) unless not rv or rv.empty? + print_format(rv, fact[:format]) unless rv.nil? or rv.empty? + end +end + + +subcommand :report, "Collect and output system information" do |report| + report.usage = "onering report" + report.opt :plugin_path, '-p', '--plugin PATH', 'Add the named path to the plugin search path' + report.opt :status, '-S', '--status STATUS', 'Set the status to report' + report.opt :tags, '-T', '--tag TAG[,...]', 'Add a tag to the report output' + report.opt :aliases, '-A', '--alias [,...]', 'Add a tag to the report output' + report.opt :id, '-I', '--id ID', 'Override the auto-detected hardware ID' + report.opt :format, '-t', '--format', 'Format the output' + + report.exec do + config = {} + %w{ + plugin_path + status + tags + aliases + id + }.each do |a| + a = a.to_sym + next if report[a].nil? + + if [:tags, :aliases].include?(a) + config[a] = report[a].split(',') + else + config[a] = report[a] + end + end + + Onering::Reporter.setup(config) + + rv = Onering::Reporter.report() + print_format(rv, report[:format] || :json) unless rv.nil? end end subcommander.go! \ No newline at end of file