#compdef fnt

_arguments \
    "1: :->mode" \
    "2: :->fonts"

case $state in
mode)
    _values \
        $state \
        {update,-u}"[update fnt package cache]" \
        {list,-l}"[lists installed fonts with glyphcount per font]" \
        info"[information about how many fonts can be installed]" \
        {help,-h}"[show help]" \
        {install,-i}"[install a font]" \
        {remove,-r}"[remove a font]" \
        {preview,-p}"[preview a font]" \
        {search,-s}"[search for font]"
    ;;

fonts)
    subcmd=${words[2]}

    case $subcmd in
    help | update | info | search) ;;
    install|-i|preview|-p)
        local -a fonts
        fonts=($(fnt search 2>/dev/null | sed 's,^google-,,;s,^fonts-,,'))
        _values \
            "fonts" $fonts
        ;;
    list|-l|remove|-r)
        local -a fontindex
        fontindex=("${(@f)$(fnt list index)}")
        [[ -z $fontindex ]] && return 0
        _values \
            "fontindex" $fontindex
        ;;
    *)
        ;;
    esac
    ;;

esac
