aboutsummaryrefslogtreecommitdiff
path: root/src/cpt
blob: a2dad7243f14b80065a0f20750a8dd0af62237dc (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
44
#!/bin/sh -ef
# shellcheck disable=1091

if command -v cpt-lib >/dev/null; then . cpt-lib; else ./cpt-lib; fi

[ "$1" ] && { arg=$1; shift; }
case "$arg" in
    --help|-h|'')
        log "Carbs Packaging Tool"
        set --
        for path in $(SEARCH_PATH=$PATH pkg_find cpt-* all -x); do
            set -- "${path#*/cpt-}" "$@"
            max=$((${#1} > max ? ${#1} : max))
        done

        for path; do
            # These are the files to be ignored.
            contains "lib readlink stat" "$path" && continue

            printf "%b->%b %-${max}s  " "${color:+\033[1;31m}" "${color:+\033[m}" "${path#*/cpt-}"
            sed -n 's/^# *//;2p' "$(command -v "cpt-$path")"
        done | sort -uk1 >&2
        exit
        ;;

    --version|-v|version) version ;;

    # Reserve these arguments for the following tools.
    a) arg=alternatives ;;
    b) arg=build ;;
    c) arg=checksum ;;
    d) arg=download ;;
    f) arg=fetch ;;
    i) arg=install ;;
    l) arg=list ;;
    r) arg=remove ;;
    s) arg=search ;;
    u) arg=update ;;
esac

util=$(SEARCH_PATH=$PATH pkg_find "cpt-$arg"* "" -x 2>/dev/null) ||
    die "'cpt $arg' is not a valid command"

"$util" "$@"