-
Notifications
You must be signed in to change notification settings - Fork 56
/
panda
executable file
·120 lines (103 loc) · 3.48 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env perl6
use Shell::Command;
use Panda;
sub listprojects($panda, :$installed) {
my $es = $panda.ecosystem;
my @projects = $es.project-list.sort.map: { $es.get-project($_) };
@projects .= grep({ $es.project-get-state($_) ne 'absent' })
if $installed;
my $max-name = @projects».name».chars.max;
my $max-ver = @projects».version».chars.max;
for @projects -> $x {
my $s = do given $es.project-get-state($x) {
when 'installed' { '[installed]' }
when 'installed-dep' { '[installed as a dependency]' }
default { '' }
}
my $url = $x.metainfo<source-url> // $x.metainfo<repo-url> // 'UNKNOWN';
printf "%-{$max-name}s %-{$max-ver}s %-27s %s\n",
$x.name, $x.version, $s, $url;
}
}
sub wrap ($str) {
return $str.comb(/ . ** 0..40 [ << | $ ]/).grep({ .chars > 0 }).join("\n" ~ " " x 36);
}
sub search-projects($panda, $string) {
for $panda.ecosystem.project-list -> $project {
my $p = $panda.ecosystem.get-project($project);
next unless $p.name ~~ /:i $string / || $p.metainfo<description> ~~ /:i $string /;
printf "%-24s %-10s %s\n",$p.name,$p.version, wrap($p.metainfo<description>);
}
}
sub projectinfo($panda, @args) {
for @args -> $p {
my $x = $panda.ecosystem.get-project($p);
if $x {
say $x.name => $x.version;
say "Depends on:" => $x.dependencies.Str if $x.dependencies;
given $panda.ecosystem.project-get-state($x) {
when 'installed' {
say "State:\t\tinstalled";
}
when 'installed-dep' {
say "State:\t\tinstalled as a dependency";
}
}
for $x.metainfo.kv -> $k, $v {
if $k ~~ none('version', 'name', 'depends') {
say $k.ucfirst => $v;
}
}
say '';
} else {
say "Project '$p' not found"
}
}
}
# default opts for MAIN
if %*ENV<PANDA_DEFAULT_OPTS> {
@*ARGS = %*ENV<PANDA_DEFAULT_OPTS> ~ (@*ARGS ?? ' ' ~ @*ARGS !! '');
}
# initialize the Panda object
my $panda;
{
my $home = $*OS eq 'MSWin32' ?? %*ENV<HOMEDRIVE> ~ %*ENV<HOMEPATH> !! %*ENV<HOME>;
my $pandadir = "$home/.panda";
mkpath $pandadir unless $pandadir.IO ~~ :d;
my $projectsfile = "$pandadir/projects.json";
$panda = Panda.new(
srcdir => "$pandadir/src",
destdir => %*ENV<DESTDIR> ?? "{cwd}/%*ENV<DESTDIR>"
!! "$home/.perl6",
statefile => "$pandadir/state",
projectsfile => "$pandadir/projects.json"
);
}
# 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 { say $! }
};
}
}
#= List all available modules
multi MAIN ('list', Bool :$installed) {
listprojects($panda, :$installed);
}
#= 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);
}
# vim: ft=perl6