35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/inspec/cli.rb', line 35
def json(target)
o = opts.dup
diagnose(o)
o['log_location'] = STDERR
configure_logger(o)
o[:backend] = Inspec::Backend.create(target: 'mock://')
o[:check_mode] = true
o[:vendor_cache] = Inspec::Cache.new(o[:vendor_cache])
profile = Inspec::Profile.for_target(target, o)
info = profile.info
info[:generator] = {
name: 'inspec',
version: Inspec::VERSION,
}
dst = o[:output].to_s
if dst.empty?
puts JSON.dump(info)
else
if File.exist? dst
puts "----> updating #{dst}"
else
puts "----> creating #{dst}"
end
fdst = File.expand_path(dst)
File.write(fdst, JSON.dump(info))
end
rescue StandardError => e
pretty_handle_exception(e)
end
|