Created
March 29, 2016 11:58
-
-
Save Altreus/a8572ea8a5b2a14b68d1 to your computer and use it in GitHub Desktop.
This file contains 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 5.014; | |
use Getopt::Long qw(:config gnu_getopt); | |
use App::Multigit qw(mg_each); | |
use Path::Class; | |
use Future; | |
my $workdir; | |
my $absolute = 1; | |
GetOptions( | |
'help|h' => sub { | |
say usage(); | |
exit 0; | |
}, | |
'workdir=s' => \$workdir, | |
'absolute!' => \$absolute, | |
); | |
chdir $workdir; | |
my $future = mg_each(\&add_environment); | |
say for $future->get; | |
sub add_environment { | |
my ($repo) = @_; | |
my $dir = $repo->config->{dir}; | |
if ($absolute) { | |
$dir = dir($dir)->absolute; | |
} | |
$dir .= '/lib'; | |
if (-d $dir) { | |
Future->done( qq(PERL5LIB="$dir:\$PERL5LIB"; export PERL5LIB;) ); | |
} | |
else { | |
Future->done | |
} | |
} | |
sub usage() { | |
<<'EOU' | |
Usage: | |
mg env [--[no-]absolute] | |
eval $(mg env) | |
Lists environment variable creation for the entire project. Currently only | |
understands PERL5LIB. | |
Options: | |
--absolute | |
--no-absolute | |
By default, the paths are output as absolute paths so it doesn't matter | |
where in the project you are. With --no-absolute, paths are output | |
relative to the mg root. | |
EOU | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment