Module: RFacter::CLI

Extended by:
SingleForwardable
Defined in:
lib/rfacter/cli.rb

Overview

RFacter Command Line Interface module

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object

Since:

  • 0.1.0



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rfacter/cli.rb', line 20

def self.run(argv)
  names = RFacter::Config.configure_from_argv!(argv)
  @config = RFacter::Config.config

  if @config.nodes.empty?
    @config.nodes['localhost'] = RFacter::Node.new('localhost')
  end

  logger.info('cli::run') { "Configured nodes: #{@config.nodes.values.map(&:id)}" }

  factset = RFacter::Factset.new(@config.nodes.values)

  node_facts = if names.empty?
                 factset.to_hash
               else
                 factset.value(names)
               end

  puts JSON.pretty_generate(node_facts)

  exit 0
end