Skip to content

Search #10

Merged
merged 2 commits into from Aug 29, 2011
View
19 bin/panda
@@ -3,7 +3,7 @@ use Shell::Command;
use Panda;
subset Command of Str where
- 'install' | 'list' | 'update' | 'info';
+ 'install' | 'list' | 'update' | 'info' | 'search';
sub installprojects($panda, @args) {
for @args -> $x {
@@ -27,6 +27,18 @@ sub listprojects($panda) {
}
}
+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 ~~ / <$string> / || $p.metainfo<description> ~~ / <$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);
@@ -67,6 +79,9 @@ sub execute(Command $c, $panda, @args) {
when 'info' {
projectinfo($panda, @args);
}
+ when 'search' {
+ search-projects($panda, @args);
+ }
}
}
@@ -119,6 +134,8 @@ Options:
Display this message and quit
install [module1 module2]
Install a modules(s)
+ search
+ Search module name/description using regex
list
List the available packages
info [module1 module2]
Something went wrong with that request. Please try again.