#compdef scrot
#
# Copyright 2024 NRK <nrk@disroot.org>
# Copyright 2025 Ratiq Narwal <ratiqnarwal@gmail.com>
#
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <https://unlicense.org/>

local -a args
local list=$($~words[1] --list-options=tsv) 2>/dev/null
for ln in ${(f)list}; do
    IFS=$'\t' local tokens=( ${=ln} )

    local sopt="${tokens[1]}"
    local lopt="${tokens[2]}"
    local argtype=${tokens[3]%%:*}
    local argdesc=${tokens[3]#*:}
    local desc="[${tokens[4]}]"

    case "$argtype" in
        R) desc+=":$argdesc" ;; # Required
        O) sopt+="+"; lopt+="=" ;; # Optional
        N) ;; # None
    esac

    [[ $lopt == "focussed" ]] && continue

    if [[ "${sopt}" = [[:alnum:]]* ]]; then
        args+=( "(-${sopt} --${lopt})-${sopt}${desc}" )
        args+=( "(-${sopt} --${lopt})--${lopt}${desc}" )
    else
        args+=( "--${lopt}${desc}" )
    fi

done
_arguments "${args[@]}"
