/
App.pm
140 lines (127 loc) · 4.52 KB
/
App.pm
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
module Panda::App {
use Shell::Command;
use Panda::Ecosystem;
use Panda::Project;
# initialize the Panda object
sub make-default-ecosystem(Str $prefix?) is export {
my $pandadir;
my CompUnit::Repository $target;
my CompUnit::Repository @repos;
if defined $prefix {
@repos.push: CompUnit::RepositoryRegistry.repository-for-spec($prefix);
}
@repos.append: <site home>.map({CompUnit::RepositoryRegistry.repository-for-name($_)});
@repos.=grep(*.defined);
for @repos {
$target = $_;
$pandadir = $target.prefix.child('panda');
try $pandadir.mkdir;
last if $pandadir.w;
}
unless $pandadir.w {
die "Found no writable directory into which panda could be installed";
}
my @extra-statefiles;
unless $prefix or $target eq CompUnit::RepositoryRegistry.repository-for-name('site') {
for @repos {
unless $target eq $_ {
@extra-statefiles.push($target.prefix.child('panda').child('state'));
}
}
}
my $panda-ecosystem = Panda::Ecosystem.new(
statefile => $pandadir.child('state'),
projectsfile => $pandadir.child('projects.json'),
extra-statefiles => @extra-statefiles
);
return $panda-ecosystem;
}
sub listprojects($panda, :$installed, :$verbose) is export {
my $es = $panda.ecosystem;
my @projects = $es.project-list.sort(*.name);
@projects .= grep({ $es.project-get-state($_) ne Panda::Project::State::absent })
if $installed;
my @saved = @projects.flatmap({ $es.project-get-saved-meta($_) || {} });
my $max-name = @projects».name».chars.max;
my $max-ver = @projects».version».chars.max;
my $max-rev = @saved.flatmap({ $_<source-revision> // '?'})».chars.max;
for @projects -> $x {
my $s = do given $es.project-get-state($x) {
when Panda::Project::State::installed { '[installed]' }
when Panda::Project::State::installed-dep { '-dependency-' }
default { '' }
}
my $meta = $s ?? $es.project-get-saved-meta($x) !! $x.metainfo;
my $url = $meta<source-url>
// $meta<support><source>
// 'UNKNOWN';
my $rev = $meta<source-revision> // '?';
my $ver = $meta<version>;
if ($verbose) {
printf "%-{$max-name}s %-12s %-{$max-ver}s %-{$max-rev}s %s\n",
$x.name, $s, $ver, $rev, $url;
}
else {
printf "%-{$max-name}s %-12s\n",
$x.name, $s;
}
}
}
sub wrap ($str) is export {
return $str.comb(/ . ** 0..40 [ << | $ ]/).grep({ .chars > 0 }).join("\n" ~ " " x 36);
}
sub search-projects($panda, $string) is export {
for $panda.ecosystem.project-list -> $p {
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) is export {
for @args -> $p {
my $x = $panda.ecosystem.get-project($p);
$x = $panda.project-from-local($p) unless $x;
if $x {
my $state = $panda.ecosystem.project-get-state($x);
my $installed;
if $state ~~ 'installed' {
$installed = $panda.ecosystem.project-get-saved-meta($x);
#note $installed.perl;
}
print $x.name;
if $x.version ne '*' {
my $foo = '';
if $installed {
$foo = " available, {$installed<version>} installed"
}
say " (version {$x.version}$foo)";
} else {
say ''
}
if my $d =$x.metainfo.<description> {
say $d
}
say 'Depends on: ', $x.dependencies.join(', ') if $x.dependencies;
print 'State: ';
given $state {
when 'installed' {
say 'installed';
}
when 'installed-dep' {
say 'installed as a dependency';
}
default {
say 'not installed'
}
}
for $x.metainfo.kv -> $k, $v {
if $k ~~ none(<version name depends description>) {
say "{$k.tc}: $v";
}
}
} else {
say "Project '$p' not found"
}
}
}
}
# vim: ft=perl6