prt-auf: refactor the list_ports subroutine
This commit is contained in:
parent
e39224cd61
commit
f7ffaabe8b
@ -78,7 +78,7 @@ if ($action eq "path") { @results = find_port_by_name($query[0],1,1,0);
|
|||||||
} elsif ($action eq "sync") { sync(@query);
|
} elsif ($action eq "sync") { sync(@query);
|
||||||
} elsif ($action =~ /^(isinst|current|sysup)$/) { ($ind, @results) = port_diff($1,@query);
|
} elsif ($action =~ /^(isinst|current|sysup)$/) { ($ind, @results) = port_diff($1,@query);
|
||||||
} elsif ($action =~ /(.*)diff$/) { ($ind, @results) = port_diff($1);
|
} elsif ($action =~ /(.*)diff$/) { ($ind, @results) = port_diff($1);
|
||||||
} elsif ($action =~ /^list(.*)/) { @results = list_ports($1);
|
} elsif ($action =~ /^list(.*)/) { @results = list_ports($1,@query);
|
||||||
} elsif ($action eq "help") { print_help();
|
} elsif ($action eq "help") { print_help();
|
||||||
} elsif ($action eq "version") { print "$title $version\n";
|
} elsif ($action eq "version") { print "$title $version\n";
|
||||||
} else { printf "Unsupported command '$action'.\n"; }
|
} else { printf "Unsupported command '$action'.\n"; }
|
||||||
@ -239,7 +239,7 @@ while (my $arg = shift) {
|
|||||||
}
|
}
|
||||||
if (! $action) { print_help(); }
|
if (! $action) { print_help(); }
|
||||||
if (($#query > -1) and
|
if (($#query > -1) and
|
||||||
($action =~ /^(diff|quickdiff|cache|list|sysup)/)) {
|
($action =~ /^(diff|quickdiff|cache|sysup)/)) {
|
||||||
print "warning: $1 takes no arguments; ignoring those given.\n";
|
print "warning: $1 takes no arguments; ignoring those given.\n";
|
||||||
}
|
}
|
||||||
if (($#query > 0) and
|
if (($#query > 0) and
|
||||||
@ -373,9 +373,9 @@ sub get_locked_and_aliased {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub who_aliased_to {
|
sub who_aliased_to {
|
||||||
my $target = shift;
|
my $target = shift; my $match = qr/(^| )$target( |$)/is;
|
||||||
my @substitutes = grep { defined $V_INST{$_} } keys %ALIASES;
|
my @substitutes = grep { defined $V_INST{$_} } keys %ALIASES;
|
||||||
@substitutes = grep { $ALIASES{$_} eq $target } @substitutes;
|
@substitutes = grep { $ALIASES{$_} =~ $match } @substitutes;
|
||||||
my $who = (@substitutes) ? $substitutes[0] : undef ;
|
my $who = (@substitutes) ? $substitutes[0] : undef ;
|
||||||
return $who;
|
return $who;
|
||||||
}
|
}
|
||||||
@ -584,7 +584,7 @@ sub port_unlock {
|
|||||||
sub list_ports {
|
sub list_ports {
|
||||||
my @found; my $subset = shift;
|
my @found; my $subset = shift;
|
||||||
|
|
||||||
if (! $subset) { # empty arg: list all valid ports
|
if (! $subset) { # default action: list all valid ports
|
||||||
foreach my $collection (@basedirs) {
|
foreach my $collection (@basedirs) {
|
||||||
opendir (DIR, $collection) or next;
|
opendir (DIR, $collection) or next;
|
||||||
foreach my $port (sort(readdir DIR)) {
|
foreach my $port (sort(readdir DIR)) {
|
||||||
@ -699,9 +699,18 @@ sub list_ports {
|
|||||||
@found = sort(keys %seen);
|
@found = sort(keys %seen);
|
||||||
} # possibilities for the recursive switch have been exhausted
|
} # possibilities for the recursive switch have been exhausted
|
||||||
} # possibilities for the filter have been exhausted
|
} # possibilities for the filter have been exhausted
|
||||||
return @found if ((! $subset) or ($subset =~ /^(orphans|locked)$/));
|
my $filter = shift; my $linewanted;
|
||||||
if (! $osearch{filter}) { return @found; }
|
return @found if ( ((! $subset) and (! $filter))
|
||||||
else { return grep {$_ !~ /$osearch{filter}/} @found; }
|
or (($subset) and ($subset =~ /^(orphans|locked)$/))
|
||||||
|
or ((! $subset) and (! $osearch{filter})) );
|
||||||
|
if ($osearch{filter}) { return grep {$_ =~ /$osearch{filter}/} @found; }
|
||||||
|
if ($filter) {
|
||||||
|
$filter =~ s/\*/.*/g;
|
||||||
|
$linewanted = qr/^$filter$/is;
|
||||||
|
return grep {$_ =~ $linewanted} @found;
|
||||||
|
} else {
|
||||||
|
return @found;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub port_diff { # find differences between the pkgdb and the repo
|
sub port_diff { # find differences between the pkgdb and the repo
|
||||||
|
Loading…
Reference in New Issue
Block a user