Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Last active October 6, 2015 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradclawsie/e5f3e3c0af212952cf05 to your computer and use it in GitHub Desktop.
Save bradclawsie/e5f3e3c0af212952cf05 to your computer and use it in GitHub Desktop.
gp.pl
#!/usr/bin/perl
use Cwd;
use Env;
use File::Copy;
use v5.20;
my $argc = scalar @ARGV;
die "use gp.pl basepath reponame" unless ($argc == 2);
my $base = $ARGV[0];
my $repo = $ARGV[1];
my $cwd = getcwd();
die "$base must be a prefix of $cwd" unless ($cwd =~ /^$base/);
die "must define GOPATH env var" unless (defined($ENV{'GOPATH'}));
my $gopath = $ENV{'GOPATH'};
$gopath .= '/src/' . $repo;
die "$gopath: not there" unless (-d $gopath);
my $src = $cwd;
$src =~ s/$base/$gopath/o;
die "$src: not there" unless (-d $src);
my @files = glob($cwd . '/*' );
my @pkg_files = ();
for my $file (@files) {
push(@pkg_files,$file) if ((-f $file) && ($file =~ /\.go$/) && ($file !~ /_test\.go$/));
}
if (0 == (scalar @pkg_files)) {
say "no files";
exit;
}
for my $file (@pkg_files) {
copy($file,$src) || die "cannot copy $file -> $src: $!";
}
my $install_cmd = 'cd ' . $src . '; go build && go install; cd ' . $cwd . ';';
say $install_cmd;
system($install_cmd);
1;
@bradclawsie
Copy link
Author

use like:

gp.pl /mnt/data/brad/repos/hovitos repo.hovitos.engineering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment