tix-tracker 0.12.0

A terminal issue tracker: markdown + YAML frontmatter issues with a kanban TUI and CLI
Documentation
#!/usr/bin/env bash
# Fake `linear-cli` for the sync integration tests, mirroring the real
# nesszer/linear-cli **0.3.28** surface: `issues create <TITLE>`, `issues
# update <ID>`, `issues list`, `issues get <ID>`, and `relations
# add|list|remove`. Same recording model as the fake `glab`: each invocation
# appends its argv plus the token env to the file named by TIX_FAKE_RECORD,
# `issues list` prints TIX_FAKE_LIST, `issues get` prints TIX_FAKE_GET, and
# TIX_FAKE_FAIL forces a failing call that leaks the token to stderr (so the
# scrub tests have something to scrub).
#
# It also emulates clap's handling of the value-bearing flags the adapter uses:
# a value passed as a *separate* argv element that begins with `-` is rejected,
# exactly as the real parser rejects it (`error: unexpected argument … found`,
# exit 2). That is what makes an argv regression — separating a markdown body
# from `-d`, or dropping the `--` before a hyphen-leading title — fail here.
set -u
record="${TIX_FAKE_RECORD:?TIX_FAKE_RECORD must be set for the fake linear-cli}"
echo "linear-cli $*" >> "$record"
echo "LINEAR_API_KEY=${LINEAR_API_KEY:-}" >> "$record"
if [ "${TIX_FAKE_FAIL:-}" != "" ]; then
    echo "LEAK:LINEAR_API_KEY=${LINEAR_API_KEY:-}" >&2
    exit "${TIX_FAKE_FAIL}"
fi

# Reject the argv shapes clap rejects: an option value supplied as a separate
# token starting with `-`, or a bare hyphen-leading token outside `--`.
check_argv() {
    local saw_dd=0 a
    while [ $# -gt 0 ]; do
        a="$1"
        if [ "$saw_dd" = 1 ]; then shift; continue; fi
        if [ "$a" = "--" ]; then saw_dd=1; shift; continue; fi
        case "$a" in
            # Attached values (`-d=…`, `-o=json`, `--output=…`) are fine.
            -[a-zA-Z]=* | --*=*) shift; continue ;;
        esac
        case "$a" in
            -t | -d | -l | -p | -s | -T | -r | -o | --output | -a | -e | --limit | --filter | --project | --assignee | --state | --team | --labels | --description | --priority | --title)
                shift
                if [ $# -eq 0 ] || [ "${1#-}" != "$1" ]; then
                    echo "error: unexpected argument '${1:-}' found" >&2
                    return 2
                fi
                shift
                ;;
            -*) echo "error: unexpected argument '$a' found" >&2; return 2 ;;
            *) shift ;;
        esac
    done
    return 0
}

sub="${1:-}"; shift 2>/dev/null || true
case "$sub" in
    issues)
        sub2="${1:-}"; shift 2>/dev/null || true
        check_argv "$@" || exit 2
        case "$sub2" in
            create)
                # `create` takes a positional title and prints the identifier.
                # Hand out distinct ids, like the fake glab does, so a run that
                # creates several issues records several remote references.
                count=$(grep -c "linear-cli issues create" "$record" 2>/dev/null || echo 1)
                id=$((99 + count))
                printf '{"identifier": "ENG-%d", "url": "https://linear.app/acme/issue/ENG-%d"}\n' "$id" "$id"
                ;;
            update)
                echo ""
                ;;
            get)
                # Default to an empty object without a brace-default expansion:
                # `${VAR:-{}}` is parsed as `${VAR:-{}` plus a literal `}`.
                if [ -n "${TIX_FAKE_GET:-}" ]; then
                    printf '%s\n' "$TIX_FAKE_GET"
                else
                    printf '{}\n'
                fi
                ;;
            list)
                printf '%s\n' "${TIX_FAKE_LIST:-[]}"
                ;;
            *)
                echo "unknown linear-cli issues subcommand: $sub2" >&2
                exit 2
                ;;
        esac
        ;;
    relations)
        sub2="${1:-}"; shift 2>/dev/null || true
        check_argv "$@" || exit 2
        case "$sub2" in
            add)
                # One edge per call: `-r <RELATION> <FROM> <TO>`.
                echo ""
                ;;
            list)
                printf '%s\n' "${TIX_FAKE_LIST:-[]}"
                ;;
            remove)
                echo ""
                ;;
            *)
                echo "unknown linear-cli relations subcommand: $sub2" >&2
                exit 2
                ;;
        esac
        ;;
    *)
        echo "unknown linear-cli subcommand: $sub" >&2
        exit 2
        ;;
esac
exit 0