# elbencho bash completion

# echo shortopts (incl. single dash) and longopts (incl. double dash).
_elbencho_opts()
{
   local shortopts longopts

   shortopts="
        -b
        -c
        -d
        -D
        -F
        -h
        -i
        -n
        -N
        -r
        -s
        -t
        -w
        "

   # all existing long option names.
   # note that options with arguments need to be declared additionally below in the corresponding
   # section for their argument type.
   longopts="
        --allelapsed
        --althttpsvc
        --backward
        --block
        --blockvaralgo
        --blockvarpct
        --clients
        --clientsfile
        --configfile
        --cores
        --cpu
        --csvfile
        --cufile
        --cufiledriveropen
        --cuhostbufreg
        --deldirs
        --delfiles
        --direct
        --dirs
        --dirsharing
        --dirstats
        --dropcache
        --dryrun
        --fadv
        --files
        --flock
        --foreground
        --gdsbufreg
        --gpuids
        --gpuperservice
        --help
        --help-all
        --help-bdev
        --help-dist
        --help-large
        --help-multi
        --help-s3
        --hosts
        --hostsfile
        --infloop
        --interrupt
        --iodepth
        --iterations
        --jsonfile
        --lat
        --lathisto
        --latpercent
        --latpercent9s
        --limitread
        --limitwrite
        --live1
        --live1n
        --livecsv
        --livecsvex
        --livejson
        --livejsonex
        --liveint
        --log
        --madv
        --mkdirs
        --mmap
        --netbench
        --netdevs
        --no0usecerr
        --nocsvlabels
        --nodelerr
        --nodetach
        --nodiocheck
        --nofdsharing
        --nolive
        --nopathexp
        --norandalign
        --nosvcshare
        --numservers
        --opslog
        --opsloglock
        --perthread
        --phasedelay
        --port
        --preallocfile
        --quit
        --rand
        --randalgo
        --randamount
        --rankoffset
        --read
        --recvbuf
        --resfile
        --respsize
        --rotatehosts
        --rwmixpct
        --rwmixthr
        --rwmixthrpct
        --s3aclget
        --s3aclgrantee
        --s3aclgrants
        --s3aclgtype
        --s3aclput
        --s3aclputinl
        --s3aclverify
        --s3baclget
        --s3baclput
        --s3btag
        --s3btagverify
        --s3bversion
        --s3bversionverify
        --s3chksumalgo
        --s3credfile
        --s3credlist
        --s3endpoints
        --s3fastget
        --s3fastput
        --s3key
        --s3listobj
        --s3listobjpar
        --s3listverify
        --s3log
        --s3logprefix
        --s3maxconns
        --s3mpusizevar
        --s3mpusplit
        --s3multidel
        --s3multiignore404
        --s3nocompress
        --s3nomd5
        --s3nompucompl
        --s3objprefix
        --s3olockcfg
        --s3olockcfgverify
        --s3otag
        --s3otagverify
        --s3randobj
        --s3region
        --s3secret
        --s3sessiontoken
        --s3sseckey
        --s3statdirs
        --s3targetgbps
        --s3virtaddr
        --sendbuf
        --servers
        --serversfile
        --service
        --sharesize
        --size
        --start
        --stat
        --svcpwfile
        --svcupint
        --svcwait
        --sync
        --threads
        --timelimit
        --treefile
        --treerand
        --treeroundup
        --treescan
        --trunc
        --trunctosize
        --verify
        --verifydirect
        --version
        --write
        --zones
        "

    echo "$shortopts $longopts"
}

_elbencho()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    opts="$(_elbencho_opts)"

    case "${prev}" in
        # options that take a string or numeric argument
        -b)
        ;&
        --block)
        ;&
        --blockvaralgo)
        ;&
        --blockvarpct)
        ;&
        --cores)
        ;&
        --dirs)
        ;&
        --fadv)
        ;&
        --files)
        ;&
        --flock)
        ;&
        --gpuids)
        ;&
        -i)
        ;&
        --iterations)
        ;&
        --iodepth)
        ;&
        --latpercent9s)
        ;&
        --limitread)
        ;&
        --limitwrite)
        ;&
        --liveint)
        ;&
        --log)
        ;&
        --madv)
        ;&
        -N)
        ;&
        -n)
        ;&
        --netdevs)
        ;&
        --numservers)
        ;&
        --phasedelay)
        ;&
        --port)
        ;&
        --randalgo)
        ;&
        --randamount)
        ;&
        --rankoffset)
        ;&
        --recvbuf)
        ;&
        --respsize)
        ;&
        --rotatehosts)
        ;&
        --rwmixpct)
        ;&
        --rwmixthr)
        ;&
        --rwmixthrpct)
        ;&
        -s)
        ;&
        --s3aclgrantee)
        ;&
        --s3aclgrants)
        ;&
        --s3aclgtype)
        ;&
        --s3chksumalgo)
        ;&
        --s3credlist)
        ;&
        --s3endpoints)
        ;&
        --s3key)
        ;&
        --s3listobj)
        ;&
        --s3log)
        ;&
        --s3logprefix)
        ;&
        --s3maxconns)
        ;&
        --s3mpusizevar)
        ;&
        --s3mpusplit)
        ;&
        --s3multidel)
        ;&
        --s3objprefix)
        ;&
        --s3region)
        ;&
        --s3secret)
        ;&
        --s3sessiontoken)
        ;&
        --s3sseckey)
        ;&
        --s3targetgbps)
        ;&
        --sendbuf)
        ;&
        --sharesize)
        ;&
        --size)
        ;&
        --start)
        ;&
        --svcupint)
        ;&
        --svcwait)
        ;&
        -t)
        ;&
        --threads)
        ;&
        --timelimit)
        ;&
        --treeroundup)
        ;&
        --verify)
        ;&
        --zones)
            return 0
        ;;

        # options that take a file/dir path argument
        -c)
        ;&
        --clientsfile)
        ;&
        --configfile)
        ;&
        --csvfile)
        ;&
        --hostsfile)
        ;&
        --jsonfile)
        ;&
        --livecsv)
        ;&
        --livejson)
        ;&
        --opslog)
        ;&
        --resfile)
        ;&
        --serversfile)
        ;&
        --svcpwfile)
        ;&
        --s3credfile)
        ;&
        --treefile)
        ;&
        --treescan)
            compopt -o filenames 2>/dev/null
            COMPREPLY=( $(compgen -f ${cur}) )
            return 0
        ;;

        # options that take a hostname argument
        --clients)
        ;&
        --hosts)
        ;&
        --servers)
            compopt -o nospace 2>/dev/null
            COMPREPLY=( $(compgen -A hostname ${cur}) )
            return 0
        ;;

        # all others
        *)
        ;;
    esac

    if [[ "${cur}" = -* ]]; then
        compopt -o filenames 2>/dev/null
        COMPREPLY=( $(compgen -f -W "${opts}" -- ${cur}) )
    else
        compopt -o filenames 2>/dev/null
        COMPREPLY=( $(compgen -f -W "" -- ${cur}) )
    fi
}

complete -F _elbencho elbencho
