Method: Inspec::InspecCLI#json

Defined in:
lib/inspec/cli.rb

#json(target) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/inspec/cli.rb', line 35

def json(target)
  diagnose
  o = opts.dup
  o[:ignore_supports] = true
  o[:backend] = Inspec::Backend.create(target: 'mock://')

  profile = Inspec::Profile.for_target(target, o)
  dst = o[:output].to_s
  if dst.empty?
    puts JSON.dump(profile.info)
  else
    if File.exist? dst
      puts "----> updating #{dst}"
    else
      puts "----> creating #{dst}"
    end
    fdst = File.expand_path(dst)
    File.write(fdst, JSON.dump(profile.info))
  end
rescue StandardError => e
  pretty_handle_exception(e)
end