1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-18 10:35:55 +00:00

Add a -s option to pkg_version, which limits output to packages

matching a given string.

PR:		26114
Submitted by:	edwin@mavetju.org (with modifications and manpage update)
MFC after:	3 days
This commit is contained in:
Bruce A. Mah 2001-06-13 20:38:46 +00:00
parent 90270b8e6f
commit 607dba5ff6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78185
2 changed files with 23 additions and 7 deletions

View File

@ -35,6 +35,7 @@
.Op Fl cdhv
.Op Fl l Ar limchar
.Op Fl L Ar limchar
.Op Fl s Ar string
.Op Ar index
.Nm
.Op Fl t Ar version1 version2
@ -146,6 +147,9 @@ Note that because some of the status flag characters are also special
to the shell, it is best to quote
.Ar limchar
with single quotes.
.It Fl s
Limit the output to those packages whose names match a given
.Ar string .
.It Fl t
Test a pair of version number strings and exit.
The output consists of one of the single characters

View File

@ -37,7 +37,8 @@ use Getopt::Std;
#
# Configuration global variables
#
$CurrentPackagesCommand = '/usr/sbin/pkg_info -aI';
$AllCurrentPackagesCommand = '/usr/sbin/pkg_info -aI';
$SelectedCurrentPackagesCommand = '/usr/sbin/pkg_info -I';
$CatProgram = "cat ";
$FetchProgram = "fetch -o - ";
$OriginCommand = '/usr/sbin/pkg_info -qo';
@ -263,13 +264,15 @@ sub GetNameAndVersion {
#
sub PrintHelp {
print <<"EOF"
Usage: pkg_version [-c] [-d debug] [-h] [-l limchar] [-L limchar] [-v] [index]
Usage: pkg_version [-c] [-d debug] [-h] [-l limchar] [-L limchar] [-s string]
[-v] [index]
pkg_version [-d debug] -t v1 v2
-c Show commands to update installed packages
-d debug Debugging output (debug controls level of output)
-h Help (this message)
-l limchar Limit output to status flags that match
-L limchar Limit output to status flags that DON\'T match
-s string Limit output to packages matching a string
-v Verbose output
index URL or filename of index file
(Default is $IndexFile)
@ -281,7 +284,7 @@ EOF
#
# Parse command-line arguments, deal with them
#
if (!getopts('cdhl:L:tv') || ($opt_h)) {
if (!getopts('cdhl:L:s:tv') || ($opt_h)) {
&PrintHelp();
exit;
}
@ -303,6 +306,9 @@ if ($opt_L) {
if ($opt_t) {
$TestFlag = 1;
}
if ($opt_s) {
$StringFlag = $opt_s;
}
if ($opt_v) {
$VerboseFlag = 1;
}
@ -341,11 +347,17 @@ else {
#
# Get the current list of installed packages
#
if ($DebugFlag) {
print STDERR "$CurrentPackagesCommand\n";
if ($StringFlag) {
if ($DebugFlag) {
print STDERR "$SelectedCurrentPackagesCommand *$StringFlag*\n";
}
open CURRENT, "$SelectedCurrentPackagesCommand \\*$StringFlag\\*|";
} else {
if ($DebugFlag) {
print STDERR "$AllCurrentPackagesCommand\n";
}
open CURRENT, "$AllCurrentPackagesCommand|";
}
open CURRENT, "$CurrentPackagesCommand|";
while (<CURRENT>) {
($packageString, $rest) = split;