text
stringlengths
0
834k
my $o = shift;
my @args = @_;
my (@reps, @reps_off, @reps_on);
my $refresh = sub {
@reps = $o->reps_all;
@reps_off = $o->reps_off;
@reps_on = $o->reps_on;
};
&$refresh;
trace(1, ""PPM: repository @args\n"");
if (@args) {
my $cmd = shift @args;
#=====================================================================
# add, delete, describe, rename commands:
#=====================================================================
if (matches($cmd, ""add"")) {
# Support for usernames and passwords.
my ($user, $pass);
{
local *ARGV;
@ARGV = @args;
GetOptions(
""username=s"" => \$user,
""password=s"" => \$pass,
);
@args = @ARGV;
}
$o->warn(<<END) and return unless @args;
repository: invalid 'add' command arguments. See 'help repository'.
END
my $url = pop @args;
my $name = join(' ', @args);
unless ($name) { # rep add http://...
$name = 'Autonamed';
for (my $i=1; $i<=@reps; $i++) {
my $tmp = ""$name $i"";
$name = $tmp and last
unless (grep { $tmp eq $_ } @reps);
}
}
my $ok = PPM::UI::repository_add($name, $url, $user, $pass);
unless ($ok->is_success) {
$o->warn($ok->msg);
return unless $ok->ok;
}
$o->rep_on($name);
$o->cache_clear('search');
}
elsif (matches($cmd, ""del|ete"")) {
my $arg = join(' ', @args);
my $gonner = $arg;
if ($arg =~ /^\d+$/) {
return unless $o->assert(
bounded(1, $arg, scalar @reps_on),
""no such active repository $arg""
);
$gonner = $reps_on[$arg - 1];
}
else {
$gonner = $o->rep_uniq($gonner);
return unless $o->assert(
$o->rep_exists($gonner),
""no such repository '$gonner'""
);
}
my $ok = PPM::UI::repository_del($gonner);
unless ($ok->is_success) {
$o->warn($ok->msg);
return unless $ok->ok;
}
$o->rep_off($gonner);
$o->cache_clear('search');
}
elsif (matches($cmd, ""des|cribe"")) {
my $arg = join(' ', @args) || 1;
my $rep = $arg;
if ($arg =~ /^\d+$/) {
return unless $o->assert(
bounded(1, $arg, scalar @reps_on),
""no such active repository $arg""
);
$rep = $reps_on[$arg - 1];
}
else {
$rep = $o->rep_uniq($rep);
return unless $o->assert(
$o->rep_exists($rep),
""no such repository '$rep'""
);
}
my $info = PPM::UI::repository_info($rep);
unless ($info->is_success) {
$o->warn($info->msg);
return unless $info->ok;
}
my $type = $o->rep_ison($rep) ? ""Active"" : ""Inactive"";
my $num = (
$o->rep_ison($rep)
? "" "" . find_index($rep, 1, @reps_on)