Module: Onering::CLI::Report
- Defined in:
- lib/onering/cli/reporter.rb
Class Method Summary collapse
Class Method Details
.configure(global = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/onering/cli/reporter.rb', line 4 def self.configure(global={}) @api = (Onering::CLI.connect(global.merge({ :autoconnect => false })) rescue nil) @opts = ::Trollop:: do "Generate a system report that can be saved or submitted to a Onering server\n\nUsage:\n onering [global] report [options]\n\nOptions:\n" opt :id, "Override the autodetected Hardware ID for this node", :short => '-I', :type => :string opt :fields, "Set the named FIELD to equal VALUE in the format FIELD=VALUE. Can be specified multiple times", :short => '-o', :type => :string, :multi => true opt :save, "Save the report output to the configured Onering server" end # initialize report generator with user options Onering::Reporter.setup({ :id => @opts[:id] }.compact) end |
.run(args) ⇒ Object
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 |
# File 'lib/onering/cli/reporter.rb', line 28 def self.run(args) report = Onering::Reporter.report().stringify_keys() # pull report overrides from the config file @api.opt('reporter.fields',{}).each do |field, value| if value.is_a?(Hash) value.coalesce(field, nil, '.').each do |k,v| report = report.set(k, v) end else report = report.set(field, value) end end # pull overrides from CLI arguments @opts[:fields].each do |field| key, value = field.split('=', 2) report = report.set(key, value) end # save if specified if @opts[:save] === true @api.connect() @api.devices.save(report['id']) do MultiJson.dump(report) end end return report end |