forked from tadzik/panda
/
panda
executable file
·73 lines (61 loc) · 1.78 KB
/
panda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env perl6
use Shell::Command;
use Panda;
use Panda::Ecosystem;
use Panda::App;
# default opts for MAIN
if %*ENV<PANDA_DEFAULT_OPTS> {
@*ARGS = %*ENV<PANDA_DEFAULT_OPTS> ~ (@*ARGS ?? ' ' ~ @*ARGS !! '');
}
# initialize the Panda object
my $panda;
{
my $pandadir;
my $destdir = %*ENV<DESTDIR>;
$destdir = "{cwd}/$destdir" if defined($destdir) && $*OS ne 'MSWin32' && $destdir !~~ /^ '/' /;
for grep(*.defined, $destdir, %*CUSTOM_LIB<site home>) -> $prefix {
$destdir = $prefix;
$pandadir = "$prefix/panda";
try mkpath $pandadir unless $pandadir.IO ~~ :d;
last if $pandadir.path.w
}
unless $pandadir.path.w {
die "Found no writable directory into which panda could be installed";
}
my $ecosystem = Panda::Ecosystem.new(
statefile => "$pandadir/state",
projectsfile => "$pandadir/projects.json",
);
$panda = Panda.new(:$ecosystem);
}
# allow switches after positionals
@*ARGS = @*ARGS.grep(/^ '-'/), @*ARGS.grep(/^ <-[-]>/);
#= Install the specified modules
multi MAIN ('install', *@modules, Bool :$notests, Bool :$nodeps) {
for @modules -> $x {
try {
$panda.resolve($x, :$notests, :$nodeps);
CATCH { when X::Panda { say $_.message } }
};
}
}
#= List all available modules
multi MAIN ('list', Bool :$installed, Bool :$verbose) {
listprojects($panda, :$installed, :$verbose);
}
#= Update the module database
multi MAIN ('update') {
$panda.ecosystem.update;
}
#= Display information about specified modules
multi MAIN ('info', *@modules) {
projectinfo($panda, @modules);
}
#= Search the name/description
multi MAIN ('search', $pattern) {
search-projects($panda, $pattern);
}
END {
rm_rf '.work' if '.work'.IO.e;
}
# vim: ft=perl6