194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/resources/package.rb', line 194
def info(package_name)
brew_path = inspec.command('brew').exist? ? 'brew' : '/usr/local/bin/brew'
cmd = inspec.command("#{brew_path} info --json=v1 #{package_name}")
return {} if cmd.exit_status.to_i != 0
pkg = JSON.parse(cmd.stdout)[0]
{
name: pkg['name'],
installed: true,
version: pkg['installed'][0]['version'],
type: 'brew',
}
rescue JSON::ParserError => e
raise Inspec::Exceptions::ResourceFailed,
'Failed to parse JSON from `brew` command. ' \
"Error: #{e}"
end
|