# zoned completion                           -*- shell-script -*-
#
# Bash completion script for the `zoned` CLI
#
# SPDX-FileCopyrightText: Samsung Electronics Co., Ltd
#
# SPDX-License-Identifier: BSD-3-Clause

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

    COMPREPLY=()

    # Complete sub-commands
    if [[ $COMP_CWORD < 2 ]]; then
        COMPREPLY+=( $( compgen -W 'enum info idfy-ctrlr idfy-ns changes errors read write append mgmt-open mgmt-close mgmt-finish mgmt-reset mgmt report --help' -- $cur ) )
        return 0
    fi

    # Complete sub-command arguments

    sub=${COMP_WORDS[1]}

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

    case "$sub" in
    
    "enum")
        opts+="--uri --flags --subnqn --hostnqn --be --help"
        ;;

    "info")
        opts+="--subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "idfy-ctrlr")
        opts+="--subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "idfy-ns")
        opts+="--subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "changes")
        opts+="--data-output --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "errors")
        opts+="--nsid --data-output --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "read")
        opts+="--slba --nlb --nsid --data-output --meta-output --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "write")
        opts+="--slba --nlb --nsid --data-input --meta-input --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "append")
        opts+="--slba --nlb --nsid --data-input --meta-input --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "mgmt-open")
        opts+="--slba --nsid --all --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "mgmt-close")
        opts+="--slba --nsid --all --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "mgmt-finish")
        opts+="--slba --nsid --all --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "mgmt-reset")
        opts+="--slba --nsid --all --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "mgmt")
        opts+="--slba --zsa --nsid --all --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    "report")
        opts+="--slba --limit --data-output --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --sync --help"
        ;;

    esac

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

    return 0
}

#
complete -o nosort -F _zoned_completions zoned

# ex: filetype=sh
