exe/hrw in hrw-0.3.6 vs exe/hrw in hrw-0.3.7

- old
+ new

@@ -1,20 +1,25 @@ #!/usr/bin/env ruby +require 'json' require 'ostruct' require 'optparse' require 'hrw' ARGV << '--help' if ARGV.empty? -options = OpenStruct.new +options = OpenStruct.new(json: false) OptionParser.new do |opt| opt.banner = "usage: #{__FILE__} [OPTIONS]" opt.on('-u', '--url [URL]', 'remote api url') do |url| options.url = url end + + opt.on('--json', 'output as json') do + options.json = true + end end.parse! if options.url.nil? if ENV.key?(Hrw::ENV) options.url = ENV[Hrw::ENV] @@ -35,10 +40,15 @@ api = Hrw::API.new(options.url) hash = api.submit(specs, scanner.package_manager) result = api.retrieve(hash) formatter = Hrw::Formatter.new -if formatter.pretty_print(result) - exit(1) +if options.json + deps = formatter.filter(result) + puts JSON.pretty_generate(deps) + + ret = deps.empty? ? 0 : 1 else - exit(0) + ret = formatter.pretty_print(result) ? 1 : 0 end + +exit(ret)