# mhmt ve mhmt-uygulama için bash tamamlaması (Türkçe ve İngilizce alt komutlar).
_mhmt_uygulama_alt() {
    # $1: alt komutun COMP_WORDS içindeki sırası
    local cur=${COMP_WORDS[COMP_CWORD]}
    if [ "$COMP_CWORD" -eq "$1" ]; then
        COMPREPLY=($(compgen -W "liste ara kur kaldir list search install remove yardim help" -- "$cur"))
        return
    fi
    case ${COMP_WORDS[$1]} in
        kur|install|kaldir|kaldır|remove|uninstall)
            COMPREPLY=($(compgen -W "-y $(mhmt uygulama --kimlikler 2>/dev/null)" -- "$cur")) ;;
        liste|list) COMPREPLY=($(compgen -W "--json" -- "$cur")) ;;
    esac
}

_mhmt() {
    local cur=${COMP_WORDS[COMP_CWORD]}
    if [ "$COMP_CWORD" -eq 1 ]; then
        COMPREPLY=($(compgen -W "uygulama guncelle destek anlik ag kutu surum yardim app update support snapshot network box version help" -- "$cur"))
        return
    fi
    case ${COMP_WORDS[1]} in
        uygulama|uygulamalar|app|apps) _mhmt_uygulama_alt 2 ;;
        guncelle|güncelle|update|upgrade) COMPREPLY=($(compgen -W "-y" -- "$cur")) ;;
        anlik|anlık|snapshot)
            [ "$COMP_CWORD" -eq 2 ] && COMPREPLY=($(compgen -W "liste al geri-don sil temizle list create rollback delete clean" -- "$cur")) ;;
        ag|network)
            if [ "$COMP_CWORD" -eq 2 ]; then COMPREPLY=($(compgen -W "durum mac dns status" -- "$cur"))
            else COMPREPLY=($(compgen -W "ac kapat on off" -- "$cur")); fi ;;
        kutu|box)
            if [ "$COMP_CWORD" -eq 2 ]; then COMPREPLY=($(compgen -W "liste olustur gir sil list create enter remove" -- "$cur"))
            else COMPREPLY=($(compgen -W "ubuntu debian arch fedora" -- "$cur")); fi ;;
    esac
}

_mhmt_uygulama() { _mhmt_uygulama_alt 1; }

complete -F _mhmt mhmt
complete -F _mhmt_uygulama mhmt-uygulama
