aboutsummaryrefslogtreecommitdiff
#!/bin/sh

## SPDX-License-Identifier: CC0-1.0
##
## Copyright (C) 2025 Woj. Kosior <koszko@koszko.org>

set -e

DESCRIPTION_SED_SCRIPT='
s/TREE$/Vanilla dependency tree/;
s/TREE-MIN/Unnecessary direct dependencies removed/;
s/TREE-DUMMY/Unnecessary dependencies dummified/;
s/TREE-FLAT/Conflicts removed where possible/;
'

if [ "$1" = "--get-measure-types" ]; then
    printf %s "VERS DEPS MULTIVER"
elif [ "$1" = "--get-tree-kinds" ]; then
    printf %s "$DESCRIPTION_SED_SCRIPT" | awk -F '[/$]' '{print $2}'
elif [ "$1" = "--make-tree-kind-description" ]; then
    sed "$DESCRIPTION_SED_SCRIPT"
elif [ "$1" = "--get-csv-columns" ]; then
    shift

    RESULTS_PATH="$1"

    shift

    COL_REFS=""

    SEP=""

    while [ -n "$1" ]; do
        HEAD_PART="$(head -1 "$RESULTS_PATH" | grep -Eo "^(.+,)?$1(,|\$)")"

        COL_NUM=$(($(printf %s "$HEAD_PART" | grep -oE ',.' | wc -l) + 1))

        COL_REFS="$COL_REFS$SEP \$$COL_NUM"

        shift

        SEP=' ","'
    done

    awk -F , "{print$COL_REFS;}" < "$RESULTS_PATH"
else
    exit 1
fi