#!/usr/bin/perl -w
# Copyright (c)2001-2002 Joe Wreschnig
# A Feta plugin to install tasks.
# Licensed under the GNU GPL.

use Getopt::Std;
use strict;

my %opts; getopts('tyqV', \%opts);

if (!$opts{'q'}) { open(QUIET, ">&STDOUT"); }
else { open(QUIET, ">>/dev/null"); }

my @packages;
foreach (@ARGV) {
 print QUIET "Looking for packages in the $_ task... ";
 my @task_packages = `feta search Task: $_`;
  print QUIET "Done. ";
 if (!@task_packages) {
  print QUIET "There is no task named $_.\n";
 } else {
  push (@packages, @task_packages);
  print QUIET scalar(@task_packages) . " packages found.\n";
 }
}

chomp @packages;

if (!@packages) {
 print STDERR "\nW: No packages were found in the tasks given.\n";
 exit 0;
}

print QUIET "\n";
exit system('feta', feta_opts(), 'install', @packages);

sub feta_opts {
 my @opts;
 foreach ('y','t','V','q') { if ($opts{$_}) { push (@opts, "-$_"); } }
 return @opts;
}
 