prt-auf: refactor the list_ports subroutine

This commit is contained in:
John McQuah 2024-09-07 15:42:55 +00:00
parent e39224cd61
commit f7ffaabe8b

View File

@ -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 =~ /^(isinst|current|sysup)$/) { ($ind, @results) = port_diff($1,@query);
} 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 "version") { print "$title $version\n";
} else { printf "Unsupported command '$action'.\n"; }
@ -239,7 +239,7 @@ while (my $arg = shift) {
}
if (! $action) { print_help(); }
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";
}
if (($#query > 0) and
@ -373,9 +373,9 @@ sub get_locked_and_aliased {
}
sub who_aliased_to {
my $target = shift;
my $target = shift; my $match = qr/(^| )$target( |$)/is;
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 ;
return $who;
}
@ -584,7 +584,7 @@ sub port_unlock {
sub list_ports {
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) {
opendir (DIR, $collection) or next;
foreach my $port (sort(readdir DIR)) {
@ -699,9 +699,18 @@ sub list_ports {
@found = sort(keys %seen);
} # possibilities for the recursive switch have been exhausted
} # possibilities for the filter have been exhausted
return @found if ((! $subset) or ($subset =~ /^(orphans|locked)$/));
if (! $osearch{filter}) { return @found; }
else { return grep {$_ !~ /$osearch{filter}/} @found; }
my $filter = shift; my $linewanted;
return @found if ( ((! $subset) and (! $filter))
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