]> pd.if.org Git - zpackage/blobdiff - zpm-log
let newpackage set additional fields
[zpackage] / zpm-log
diff --git a/zpm-log b/zpm-log
index f4fdab87ca64158a2ebfa6c82cdfae046ba37314..441d15709930da7093491cf6ed43aeb4202cf7d5 100755 (executable)
--- a/zpm-log
+++ b/zpm-log
@@ -6,17 +6,24 @@
 #-i insert, otherwise search
 
 op=search
-action='log'
+action=
+json=0
+verbose=0
 
 pkgfile=${ZPMDB:-/var/lib/zpm/local.db}
 
-while getopts f:t:a:T:i opt; do
+order=asc
+
+while getopts f:t:a:T:ijvr opt; do
        case $opt in
                f) pkgfile="$OPTARG" ;;
                t) target="$OPTARG" ;;
                a) action="$OPTARG" ;;
                T) timestamp="$OPTARG" ;;
                i) op=insert ;;
+               j) json=1 ;;
+               v) verbose=1 ;;
+               r) order=desc ;;
                *) printf '%s unknown option %s\n' "$0" "$opt" ; exit 1 ;;
        esac
 done
@@ -48,23 +55,34 @@ if [ $op = 'insert' ]; then
        printf ';\n'
 } | zpm shell $pkgfile
 
+if [ $verbose -ne 0 ]; then
+       printf "%s %s %s\n" "$action" "$target" "$*" 1>&2
+fi
+
 fi
 
+cols='ts,target,action,info'
+
 if [ $op = 'search' ]; then
+
+if [ $json -eq 1 ]; then
+       cols="json_group_array(json_object('ts',ts,'target',target,'action',action,'info',info))"
+fi
+
 {
-       printf 'select ts,action,target,info from zpmlog where\n';
+       printf ".separator ' '\n"
+       printf 'select %s from zpmlog where\n' "$cols";
        if [ -n "$timestamp" ]; then
                printf "ts >= '%s' and " "$timestamp"
        fi
 
        if [ -n "$action" ]; then
-               printf "action = '%s' and " "$action"
+               printf "action like '%s' and " "$action"
        fi
        if [ -n "$target" ]; then
-               printf "target = '%s' and " "$target"
+               printf "target like '%s' and " "$target"
        fi
-       printf "true;\n"
+       printf "true order by ts $order;\n"
 } | zpm shell $pkgfile
 
 fi
-