]> pd.if.org Git - zpackage/commitdiff
add zpm-list
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 23 Sep 2018 14:42:19 +0000 (14:42 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 24 Sep 2018 10:40:18 +0000 (10:40 +0000)
zpm-list [new file with mode: 0755]

diff --git a/zpm-list b/zpm-list
new file mode 100755 (executable)
index 0000000..471a280
--- /dev/null
+++ b/zpm-list
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# zpm-list [-s status] [-vn] [ -f pkgfile ] [pkgid ...]
+
+verbose=0
+nameonly=0
+
+while getopts :s:f:vn opt; do
+       case $opt in
+               f) pkgfile="$OPTARG" ;;
+               s) status="$OPTARG" ;;
+               v) verbose=1 ;;
+               n) nameonly=1 ;;
+       esac
+done
+shift $(( OPTIND - 1))
+
+: ${pkgfile:=$ZPMDB}
+
+if [ -z "$pkgfile" ]; then
+       echo "must specify package file"
+       exit 1
+fi
+
+if [ -n "$status" ]; then
+       status=$(zpm quote "$status")
+fi
+
+if [ $nameonly -eq 0 ]; then
+       cols="pkgid"
+else
+       cols="package"
+fi
+
+if [ $verbose -eq 1 ]; then
+       cols="$cols,coalesce(status,'-')"
+fi
+
+if [ -n "$status" ]; then
+       where="where status = '$status'"
+fi
+
+pkgid=$1
+
+if [ -n "$pkgid" ]; then
+       eval $(zpm parse -E "$pkgid")
+       if [ -n "$package" ]; then
+               package=$(zpm quote "$package")
+               where="$where and package = '$package'"
+       fi
+       if [ -n "$version" ]; then
+               version=$(zpm quote "$version")
+               where="$where and version = '$version'"
+       fi
+       if [ -n "$release" ]; then
+               release=$(zpm quote "$release")
+               where="$where and release = '$release'"
+       fi
+fi
+
+zpm shell $pkgfile <<EOS
+.separator "\t"
+select $cols from packages_pkgid $where
+;
+EOS
+