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

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

    COMPREPLY=()

    # Complete sub-commands
    if [[ $COMP_CWORD < 2 ]]; then
        COMPREPLY+=( $( compgen -W 'list enum info idfy idfy-ns idfy-ctrlr idfy-cs log log-erri log-health log-fdp-config log-ruhu log-fdp-stats log-fdp-events feature-get feature-set set-fdp-events format sanitize fdp-ruhs fdp-ruhu pioc padc library-info dsm subsystem-reset show-regs ctrlr-reset ns-rescan --help' -- $cur ) )
        return 0
    fi

    # Complete sub-command arguments

    sub=${COMP_WORDS[1]}

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

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

    "enum")
        opts+="--uri --flags --subnqn --hostnqn --be --help"
        ;;

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

    "idfy")
        opts+="--cns --cntid --nsid --setid --uuid --data-output --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

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

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

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

    "log")
        opts+="--lid --lsp --lpo-nbytes --nsid --rae --data-nbytes --data-output --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

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

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

    "log-fdp-config")
        opts+="--nsid --data-nbytes --data-output --lsi --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "log-ruhu")
        opts+="--nsid --data-output --limit --lsi --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "log-fdp-stats")
        opts+="--nsid --data-output --lsi --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "log-fdp-events")
        opts+="--nsid --limit --data-output --lsi --lsp --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "feature-get")
        opts+="--fid --nsid --sel --cdw11 --data-output --data-nbytes --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "feature-set")
        opts+="--fid --feat --nsid --save --cdw12 --data-input --data-nbytes --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "set-fdp-events")
        opts+="--fid --feat --nsid --save --cdw12 --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "format")
        opts+="--nsid --lbafl --lbafu --mset --ses --pi --pil --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "sanitize")
        opts+="--sanact --ause --ovrpat --owpass --oipbp --nodas --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

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

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

    "pioc")
        opts+="--cdw0 --cdw1 --cdw2 --cdw3 --cdw4 --cdw4 --cdw5 --cdw6 --cdw7 --cdw8 --cdw9 --cdw10 --cdw11 --cdw12 --cdw13 --cdw14 --cdw15 --opcode --nsid --data-input --data-output --data-nbytes --meta-input --meta-output --meta-nbytes --verbose --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "padc")
        opts+="--cdw0 --cdw1 --cdw2 --cdw3 --cdw4 --cdw4 --cdw5 --cdw6 --cdw7 --cdw8 --cdw9 --cdw10 --cdw11 --cdw12 --cdw13 --cdw14 --cdw15 --opcode --nsid --data-input --data-output --data-nbytes --meta-input --meta-output --meta-nbytes --verbose --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

    "library-info")
        opts+="--help"
        ;;

    "dsm")
        opts+="--nsid --ad --idw --idr --slba --llb --subnqn --hostnqn --be --dev-nsid --admin --mem --direct --help"
        ;;

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

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

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

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

    esac

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

    return 0
}

#
complete -o nosort -F _xnvme_completions xnvme

# ex: filetype=sh
