Method: Inspec::InspecCLI#shell_func

Defined in:
lib/inspec/cli.rb

#shell_funcObject



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/inspec/cli.rb', line 190

def shell_func
  diagnose
  o = opts.dup

  json_output = ['json', 'json-min'].include?(opts['format'])
  log_device = json_output ? nil : STDOUT
  o[:logger] = Logger.new(log_device)
  o[:logger].level = get_log_level(o.log_level)

  if o[:command].nil?
    runner = Inspec::Runner.new(o)
    return Inspec::Shell.new(runner).start
  end

  run_type, res = run_command(o)
  exit res unless run_type == :ruby_eval

  # No InSpec tests - just print evaluation output.
  res = (res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)) if json_output
  puts res
  exit 0
rescue RuntimeError, Train::UserError => e
  $stderr.puts e.message
rescue StandardError => e
  pretty_handle_exception(e)
end