text
stringlengths
0
834k
returns:
Targets:
1. ActivePerl 618
* 2. ActivePerl 629
This shows that there are two available targets, and that the second
target (ActivePerl 629) is currently the default (as shown by the
asterisk). Using multiple targets, you can manage multiple installations
of Perl from a single command-line.
END
sub comp_targets {
my $o = shift;
my ($word, $line, $start) = @_;
my @words = $o->line_parsed($line);
my $words = scalar @words;
my @compls;
my @targs = PPM::UI::target_list()->result_l;
# only return 'set' and 'describe' when we're completing the second word
if ($words == 1 or $words == 2 and $start != length($line)) {
@compls = ('set', 'select', 'describe', 'rename', 1 .. scalar @targs);
return $o->completions($word, \@compls);
}
if ($words == 2 or $words == 3 and $start != length($line)) {
# complete 'set'
if (matches($words[1], 's|et')) {
my $targ = $o->conf('target');
@compls = map { $_->[0] }
grep { $_->[1] }
PPM::UI::target_config_keys($targ)->result_l;
return $o->completions($word, \@compls);
}
# complete 'describe' and 'rename'
elsif (matches($words[1], 'd|escribe')
or matches($words[1], 'r|ename')
or matches($words[1], 's|elect')) {
return $o->completions($word, [1 .. scalar @targs]);
}
}
();
}
sub run_targets {
my $o = shift;
my @args = @_;
trace(1, ""PPM: target @args\n"");
my @targets = PPM::UI::target_list()->result_l;
my $targets = @targets;
# No arguments: print targets
if (@args) {
my ($cmd, @rest) = @args;
if ($cmd =~ /^\d+$/
or matches($cmd, 'se|lect')) {
my $num = $cmd =~ /^\d+$/ ? $cmd :
$rest[0] =~ /^\d+$/ ? $rest[0] :
do {
my $n = find_index($rest[0], 1, @targets);
if ($n < 1) {
$o->warn(""No such target '$rest[0]'.\n"");
return;
}
$n;
};
# QA the number: is it too high/low?
unless(bounded(1, $num, $targets)) {
$o->warn(""No such target number '$num'.\n"");
return;
}
else {
$o->conf('target', $targets[$num-1]);
$o->cache_clear('query');
}
}
elsif (matches($cmd, 'r|ename')) {
my ($oldnum, $newname) = @rest;
$oldnum = $oldnum =~ /^\d+$/ ? $oldnum :
do {
my $n = find_index($oldnum, 1, @targets);
if ($n < 1) {
$o->warn(""No such target '$oldnum'.\n"");
return;
};
$n;
};
unless (defined $oldnum && $oldnum =~ /^\d+$/) {
$o->warn(<<END);
target: '$cmd' requires a numeric argument. See 'help $cmd'.
END
return;
}
unless (bounded(1, $oldnum, $targets)) {
$o->warn(""No such target number '$oldnum'.\n"");
return;
}
unless (defined $newname and $newname) {
$newname = '' unless defined $newname;