# xnvme_tests_buf completion                           -*- shell-script -*-
#
# Bash completion script for the `xnvme_tests_buf` CLI
#
# Copyright (C) Simon A. F. Lund <simon.lund@samsung.com>
# SPDX-License-Identifier: Apache-2.0

_xnvme_tests_buf_completions()
{
    local cur=${COMP_WORDS[COMP_CWORD]}
    local sub=""
    local opts=""

    COMPREPLY=()

    # Complete sub-commands
    if [[ $COMP_CWORD < 2 ]]; then
        COMPREPLY+=( $( compgen -W 'buf_alloc_free buf_virt_alloc_free --help' -- $cur ) )
        return 0
    fi

    # Complete sub-command arguments

    sub=${COMP_WORDS[1]}

    if [[ "$sub" != "enum" ]]; then
        opts+="/dev/nvme* "
    fi

    case "$sub" in
    
    "buf_alloc_free")
        opts+="--count --dev-nsid --be --help"
        ;;

    "buf_virt_alloc_free")
        opts+="--count --dev-nsid --be --help"
        ;;

    esac

    COMPREPLY+=( $( compgen -W "$opts" -- $cur ) )

    return 0
}

#
complete -o nosort -F _xnvme_tests_buf_completions xnvme_tests_buf

# ex: filetype=sh
