aboutsummaryrefslogtreecommitdiff
path: root/src/cpt-list
blob: a924091fac8ee4c2cca4045a95bfa6f028a241cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh -ef
# List installed packages

parser_definition() {
    setup REST help:usage -- \
        "usage: ${0##*/} [-cq] pkg..." \
        "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" \
          "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
    pkg_list "$@"
fi