Last active
August 29, 2015 14:16
-
-
Save dolzenko/2d3271d44719bfe68955 to your computer and use it in GitHub Desktop.
Prints missing/unused Go deps for https://github.com/bsm/mgmt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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