From ad889dfb5ca9ac2a30ad988d6f1d730099c32e01 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 1 Mar 2019 05:17:09 +0000 Subject: [PATCH] update rmpackage --- doc/zpm-findpkg.8 | 78 +++++++++++++++++++++++++++++++++++++++++++++ doc/zpm-rmpackage.8 | 24 +++++++++++--- zpm-rmpackage | 14 ++++---- 3 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 doc/zpm-findpkg.8 diff --git a/doc/zpm-findpkg.8 b/doc/zpm-findpkg.8 new file mode 100644 index 0000000..9b34258 --- /dev/null +++ b/doc/zpm-findpkg.8 @@ -0,0 +1,78 @@ +.TH zpm-findpkg 8 2019-02-22 "ZPM 0.3" +.SH NAME +zpm-findpkg \- find package ids +.SH SYNOPSIS +.B zpm findpkg +[ +.BI \-f " pkgfile" +] +[ +.B \-Imre +] +[ +.BI \-s status +] +[ +.BI \-S status +] +.I package +[ +.I package +] +.SH DESCRIPTION +\fBzpm-findpkg\fR +finds packages in package databases. A package may be specified as +an incomplete package id. If found, the full package id will +be printed to stdout. Where more than one package matches, +the latest one (as if by zpm-vercmp) will be found. +.PP +If two arguments are given, they form an inclusive range of packages. +Either may be a partial package id, but both must have the same +package name. +.SH OPTIONS +.TP +.BI \-f package +specify the package file to find packages in +.TP +.B \-I +Only find installed packages. Equivalent to \fB\-s installed\fR. +.TP +.B \-m +This reverses the sense of the arguments. The first argument is +taken as the maximum package version to find. A second argument, +if given, is taken as the minimum. Implies \-r. +.TP +.B \-r +Find package within a range, rather than an exact match. The +first package argument is the inclusive lower bound. The second +argument, if provides, is the inclusive upper bound. If no +second argument is given, there is no upper bound. +This option is implied if two arguments are given. +.TP +.B \-l +Find the earliest package in a range, as if compared by zpm-vercmp. +Implies \-r. +.TP +.BI \-s status +Add \fIstatus\fR to the set of package statuses to match. If the +list is empty, any status will match. +.TP +.BI \-S status +Add \fIstatus\fR to the set of package statuses to exclude from +matching. If a given status is listed both in include and exclude, +the package status will be excluded. +.SH EXAMPLES +.TP +.B zpm findpkg foo +find the latest version of foo in the default database. +.SH EXIT STATUS +0 on success non zero on failure +.SH FILES +/var/lib/zpm/local.db +.SH ENVIRONMENT +ZPMDB +.SH AUTHOR +Nathan Wagner +.SH SEE ALSO +.BR zpm (8) +.BR zpm-vercmp (8) diff --git a/doc/zpm-rmpackage.8 b/doc/zpm-rmpackage.8 index cffd87c..63c2788 100644 --- a/doc/zpm-rmpackage.8 +++ b/doc/zpm-rmpackage.8 @@ -1,10 +1,7 @@ -.TH zpm-rmpackage 8 2019-02-15 "ZPM 0.3" +.TH zpm-rmpackage 8 2019-02-28 "ZPM 0.3" .SH NAME zpm-rmpackage \- remove packages from a database .SH SYNOPSIS - f) pkgfile="$OPTARG" ;; - v) verbose=1 ;; - m) message="$OPTARG" ;; .B zpm rmpackage [ .BI -f " pkgfile" @@ -13,6 +10,12 @@ zpm-rmpackage \- remove packages from a database .BI -m " message" ] [ +.BI -s " status" +] +[ +.BI -S " status" +] +[ .B -v ] .RI [ package ...] @@ -42,6 +45,17 @@ specify the package file to find packages in .BI \-m message specify a message for each log message. .TP +.BI \-s status +Require that packages listed have the given status. This is primarily +a safety feature so that you don't accidentally remove installed packages +from the database. +Passed through to zpm-findpkg and may be given more than once. +.TP +.BI \-S status +Require that packages not have the given status. Useful for excluding +installed packages without specifying other statuses explicitly. +Passed through to zpm-findpkg and may be given more than once. +.TP .B \-v Verbose mode. .SH EXAMPLES @@ -59,5 +73,5 @@ ZPM_PACKAGEFILE Nathan Wagner .SH SEE ALSO .BR zpm (8) -.BR zpm-findpackage (8) +.BR zpm-findpkg (8) .BR zpm-log (8) diff --git a/zpm-rmpackage b/zpm-rmpackage index 4e8f107..98eac6e 100755 --- a/zpm-rmpackage +++ b/zpm-rmpackage @@ -5,11 +5,13 @@ pkgfile=${ZPM_PACKAGE_FILE:-${ZPMDB:-/var/lib/zpm/local.db}} verbose=0 # newpackage -f pkgfile $pkgid -while getopts :f:vm: opt; do +while getopts :f:vm:s:S: opt; do case $opt in f) pkgfile="$OPTARG" ;; v) verbose=1 ;; m) message="$OPTARG" ;; + s) status="$status -s $OPTARG" ;; + S) exclude="$exclude -S $OPTARG" ;; esac done shift $(( OPTIND - 1)) @@ -35,14 +37,14 @@ fi { printf ".bail on\n" + printf ".echo on\n" printf "begin;\n" for pkgstr in "$@"; do - pkgid=$(zpm findpkg -f $pkgfile "$pkgstr") + pkgid=$(zpm findpkg $status $exclude -f $pkgfile "$pkgstr") + if [ -z "$pkgid" ]; then + continue; + fi if [ $verbose -gt 0 ]; then - if [ -z "$pkgid" ]; then - warn "$pkgstr not found" - continue; - fi if [ $verbose -gt 1 ]; then warn "found %s -> %s\n" "$pkgstr", "$pkgid" fi -- 2.40.0