aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2023-04-17 12:52:08 +0000
committermerakor <cem@ckyln.com>2023-04-17 12:52:08 +0000
commitdfb0841da67373ab9f962f8ede51669a30af3e43 (patch)
tree244748e83ed4015e9f228c7fb87e283bc9420ad2
parentee81cbb161e5f6dbf256f70978264e937d364f98 (diff)
downloadcpt-dfb0841da67373ab9f962f8ede51669a30af3e43.tar.gz
cpt-list: add operation to check package version
FossilOrigin-Name: cb29ddc4ff97a89174e0345cd0e4311eb76203a11608dfe117611be7445629ce
-rwxr-xr-xsrc/cpt-list19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/cpt-list b/src/cpt-list
index fcb1f49..a924091 100755
--- a/src/cpt-list
+++ b/src/cpt-list
@@ -4,25 +4,38 @@
parser_definition() {
setup REST help:usage -- \
"usage: ${0##*/} [-cq] pkg..." \
- "or: ${0##*/} -C pkg true-statement false-statement"
+ "or: ${0##*/} -C pkg true-statement false-statement" \
+ "or: ${0##*/} -V pkg version release"
msg -- '' 'Options:'
flag CURRENT -c --current -- "Use the current directory as a package"
flag quiet -q --quiet -- "Make the operation quiet"
- param PKG -C --check label:" -C,--check PKG TRUE FALSE" -- \
- "Check if PKG exists and return the string of TRUE if"\
+ param PKG -C --check label:"-C, --check PKG TRUE FALSE" -- \
+ "Check if PKG exists and return the string of TRUE if" \
"it exists, and the string of FALSE if it doesn't." \
"Useful for optional packaging."
+ flag VERSIONCHECK -V --version-check label:"-V, --version-check PKG VER REL" -- \
+ "Check if given package exists in the given version" \
+ "and release numbers. Returns success or failure depending" \
+ "on the outcome."
global_options
}
if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi
+# There is no proper way I can think of doing this directly in the option
+# parser, so let's make sure that only one operation is selected.
+[ "$PKG" ] && [ "$VERSIONCHECK" ] &&
+ die "Only one operation between '-C' and '-V' can be selected."
+
+
if [ "$PKG" ]; then
if pkg_list "$PKG" >/dev/null 2>&1; then
printf %s "$1"
else
printf %s "$2"
fi
+elif [ "$VERSIONCHECK" ]; then
+ pkg_list "$1" | grep -Fq "$1 $2 $3"
else
[ "$CURRENT" ] && set -- "${PWD##*/}"
[ "$quiet" ] && exec >/dev/null 2>&1