_hson() {
    local i cur prev opts cmd
    COMPREPLY=()
    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
        cur="$2"
    else
        cur="${COMP_WORDS[COMP_CWORD]}"
    fi
    prev="$3"
    cmd=""
    opts=""

    for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="hson"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        hson)
            opts="-c -u -n -H -m -C -N -f -t -g -r -i -h -V --bytes --chars --lines --count-headers --no-space --no-newline --no-header --tree --no-sort --compact --string-cap --global-bytes --global-lines --tail --head --format --template --indent --color --no-color --glob --recursive --input-format --debug --grep --igrep --weak-grep --weak-igrep --capped-grep --capped-igrep --count-matches --grep-show --completions --help --version [INPUT]..."
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --bytes)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -c)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --chars)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -u)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --lines)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -n)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --string-cap)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --global-bytes)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -C)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --global-lines)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -N)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --format)
                    COMPREPLY=($(compgen -W "auto json yaml text" -- "${cur}"))
                    return 0
                    ;;
                -f)
                    COMPREPLY=($(compgen -W "auto json yaml text" -- "${cur}"))
                    return 0
                    ;;
                --template)
                    COMPREPLY=($(compgen -W "strict default detailed" -- "${cur}"))
                    return 0
                    ;;
                -t)
                    COMPREPLY=($(compgen -W "strict default detailed" -- "${cur}"))
                    return 0
                    ;;
                --indent)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --glob)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                -g)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --input-format)
                    COMPREPLY=($(compgen -W "json jsonl yaml text" -- "${cur}"))
                    return 0
                    ;;
                -i)
                    COMPREPLY=($(compgen -W "json jsonl yaml text" -- "${cur}"))
                    return 0
                    ;;
                --grep)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --igrep)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --weak-grep)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --weak-igrep)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --capped-grep)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --capped-igrep)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --grep-show)
                    COMPREPLY=($(compgen -W "matching all" -- "${cur}"))
                    return 0
                    ;;
                --completions)
                    COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    complete -F _hson -o nosort -o bashdefault -o default hson
else
    complete -F _hson -o bashdefault -o default hson
fi
