Sha256: 14a48a3c6fc5a968b58ac889afe242422157d66bac0b5cc13704c1defb29bf2d

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

#!/usr/bin/env ruby
require 'json'
require 'ostruct'
require 'optparse'

require 'hrw'

ARGV << '--help' if ARGV.empty?

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]
  else
    puts '[-] no url'
    exit(1)
  end
end

scanner = Hrw::Detector.detect
if scanner.nil?
  puts '[-] can not detect package manager, skip'
  exit(0)
end

specs = scanner.scan
if specs.empty?
  puts '[-] no packages found'
  exit(0)
end

api = Hrw::API.new(options.url)
hash = api.submit(specs, scanner.package_manager)
result = api.retrieve(hash)

formatter = Hrw::Formatter.new
if options.json
  deps = formatter.filter(result)
  puts JSON.pretty_generate(deps)

  ret = deps.empty? ? 0 : 1
else
  ret = formatter.pretty_print(result) ? 1 : 0
end

exit(ret)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hrw-0.3.9 exe/hrw