Skip to content

Instantly share code, notes, and snippets.

@dolzenko
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolzenko/2d3271d44719bfe68955 to your computer and use it in GitHub Desktop.
Save dolzenko/2d3271d44719bfe68955 to your computer and use it in GitHub Desktop.
Prints missing/unused Go deps for https://github.com/bsm/mgmt
require 'json'
require 'set'
myself = `go list`.strip
deps = Set.new
`go list ./...`.each_line do |dep|
pdeps = JSON.parse(`mgmt go list -json #{dep}`)
deps += pdeps['Deps']
deps += pdeps['TestImports'] if pdeps['TestImports']
end
all = deps.select do |dep|
dep.split('/').first.include? '.'
end.map do |dep|
dep.split('/')[0..2].join('/')
end.uniq.sort
existing = File.read('Gopherfile').each_line.map do |l|
l.strip.split(/\s+/)
end.reject do |l|
l.empty?
end.map do |l|
l.first
end
missing = all - existing - [myself]
unused = existing - all - [myself]
puts "Missing packages:\n#{missing.join "\n"}"
puts "Unused packages:\n#{unused.join "\n"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment