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

- (Application) initialize

A new instance of Application



64
65
66
67
68
69
70
# File 'lib/ohai/application.rb', line 64

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

+ (Object) exit!(msg, err = 1)



116
117
118
119
# File 'lib/ohai/application.rb', line 116

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

+ (Object) fatal!(msg, err = 1)

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



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

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

Instance Method Details

- (Object) configure_logging



87
88
89
90
# File 'lib/ohai/application.rb', line 87

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

- (Object) configure_ohai



78
79
80
81
82
83
84
85
# File 'lib/ohai/application.rb', line 78

def configure_ohai
  @attributes = parse_options

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

- (Object) run



72
73
74
75
76
# File 'lib/ohai/application.rb', line 72

def run
  configure_ohai
  configure_logging
  run_application
end

- (Object) run_application



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ohai/application.rb', line 92

def run_application
  ohai = Ohai::System.new
  if Ohai::Config[:file]
    ohai.from_file(Ohai::Config[:file])
  else
    ohai.all_plugins
  end
  if @attributes.length > 0
    @attributes.each do |a|
      puts ohai.attributes_print(a)
    end
  else
    puts ohai.json_pretty_print
  end
end