Last active
February 4, 2018 13:59
-
-
Save yfuruyama/6b057bba0639a1dcae08d08e8bf30084 to your computer and use it in GitHub Desktop.
List all installed go packages
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
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use File::Find qw/find/; | |
| sub _find_packages { | |
| my $root = shift; | |
| my $pkg_path = $root . '/pkg'; | |
| my @packages; | |
| find(sub { | |
| return unless $_ =~ m!\.a$!; | |
| return if $File::Find::name =~ m!/internal/!; | |
| my ($arch, $pkg) = $File::Find::name =~ m!${pkg_path}/([^/]+)/(.+)\.a$!; | |
| push @packages, $pkg; | |
| }, $pkg_path); | |
| return @packages; | |
| } | |
| sub _uniq { | |
| my %h = map { $_ => 1 } @_; | |
| return keys(%h); | |
| } | |
| my @packages = ('builtin'); | |
| push(@packages, sort(_uniq(_find_packages($ENV{GOROOT})))); | |
| push(@packages, sort(_uniq(_find_packages($ENV{GOPATH})))); | |
| print($_ . "\n") for (@packages); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment