From 58638238a074eb26550d728f7058d042cc83c9ed Mon Sep 17 00:00:00 2001 From: bmah Date: Wed, 13 Jun 2001 20:38:46 +0000 Subject: 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 --- usr.sbin/pkg_install/version/pkg_version.1 | 4 ++++ usr.sbin/pkg_install/version/pkg_version.pl | 26 +++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/pkg_install/version/pkg_version.1 b/usr.sbin/pkg_install/version/pkg_version.1 index a771c04..e46122b 100644 --- a/usr.sbin/pkg_install/version/pkg_version.1 +++ b/usr.sbin/pkg_install/version/pkg_version.1 @@ -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 diff --git a/usr.sbin/pkg_install/version/pkg_version.pl b/usr.sbin/pkg_install/version/pkg_version.pl index 8647741..adf14ec 100755 --- a/usr.sbin/pkg_install/version/pkg_version.pl +++ b/usr.sbin/pkg_install/version/pkg_version.pl @@ -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 () { ($packageString, $rest) = split; -- cgit v1.1