Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 75 lines (63 sloc) 1.717 kb
#!/usr/bin/perl
use JSON::XS;
use Term::ANSIColor;
use Getopt::Long;
use autodie;
use 5.012;
my @packages; #here be database
my $dburl = 'http://pacnet.karbownicki.com/api/packages/';
my $dbfile = $ENV{'HOME'} . '/.config/pacnet.db';
sub printpackage {
my $p = shift;
say colored('*', 'green'), ' ',
$p->{'category__name'} .'/',
colored($p->{'name'}, 'bold'), "\n ",
colored("Version: \t", 'green'), $p->{'version'}, "\n ",
colored("Description:\t", 'green'), $p->{'description'}, "\n";
}
sub packagestring {
my $p = shift;
return $p->{'category__name'} . '/' . $p->{'name'};
}
sub getdb {
require LWP::Simple;
unless(LWP::Simple::getstore($dburl, $dbfile) == 200) {
say "Failed downloading the package database";
exit 1;
}
}
sub readdb {
getdb unless -f $dbfile;
open my $db, '<', $dbfile;
my $json = do { local $/; <$db> }; # slurp
close $db;
@packages = @{decode_json($json)};
}
sub usage {
print <<'END';
Usage: pacnet <regexp>
Flags: -h (--help) => show usage information
-s (--sync) => synchronise package database
--nocolor => turn off colouring
END
}
sub MAIN {
my $res = GetOptions(
"s|sync" => sub { getdb },
"h|help" => sub { usage },
"nocolor" => sub { $ENV{'ANSI_COLORS_DISABLED'} = 1 },
);
readdb;
if (scalar @ARGV) {
my $count = 0;
printpackage($_) && $count++
for grep { packagestring($_) =~ $ARGV[0] } @packages;
if ($count == 0) {
say "No matches found";
} elsif ($count > 1) {
say "Found $count matches.";
}
}
}
MAIN;
# vim: ft=perl
Jump to Line
Something went wrong with that request. Please try again.