Class: Ohai::Application

Inherits:
Object
  • Object
show all
Includes:
Mixlib::CLI
Defined in:
lib/ohai/application.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.


59
60
61
62
63
64
65
# File 'lib/ohai/application.rb', line 59

def initialize
  super

  # Always switch to a readable directory. Keeps subsequent Dir.chdir() {}
  # from failing due to permissions when launched as a less privileged user.
  Dir.chdir("/")
end

Class Method Details

.exit!(msg, err = -1)) ⇒ Object


109
110
111
112
# File 'lib/ohai/application.rb', line 109

def exit!(msg, err = -1)
  Chef::Log.debug(msg)
  Process.exit err
end

.fatal!(msg, err = -1)) ⇒ Object

Log a fatal error message to both STDERR and the Logger, exit the application


103
104
105
106
107
# File 'lib/ohai/application.rb', line 103

def fatal!(msg, err = -1)
  STDERR.puts("FATAL: #{msg}")
  Chef::Log.fatal(msg)
  Process.exit err
end

Instance Method Details

#configure_loggingObject


83
84
85
86
# File 'lib/ohai/application.rb', line 83

def configure_logging
  Ohai::Log.init(Ohai::Config[:log_location])
  Ohai::Log.level = Ohai::Config[:log_level]
end

#configure_ohaiObject


73
74
75
76
77
78
79
80
81
# File 'lib/ohai/application.rb', line 73

def configure_ohai
  @attributes = parse_options
  @attributes = nil if @attributes.empty?

  Ohai::Config.merge!(config)
  if Ohai::Config[:directory]
    Ohai::Config[:plugin_path] << Ohai::Config[:directory]
  end
end

#runObject


67
68
69
70
71
# File 'lib/ohai/application.rb', line 67

def run
  configure_ohai
  configure_logging
  run_application
end

#run_applicationObject


88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ohai/application.rb', line 88

def run_application
  ohai = Ohai::System.new
  ohai.all_plugins(@attributes)

  if @attributes
    @attributes.each do |a|
      puts ohai.attributes_print(a)
    end
  else
    puts ohai.json_pretty_print
  end
end