# bash completion for synex-mkboot
_synex_mkboot() {
    local cur prev words cword
    _init_completion || return

    local commands="list write"
    local global_opts="--version --help"

    # Find the subcommand: first non-option word after the program name.
    local cmd="" i
    for ((i = 1; i < cword; i++)); do
        case "${words[i]}" in
            -*) ;;
            *) cmd="${words[i]}"; break ;;
        esac
    done

    if [[ -z "$cmd" ]]; then
        COMPREPLY=( $(compgen -W "$commands $global_opts" -- "$cur") )
        return
    fi

    case "$cmd" in
        write)
            if [[ "$cur" == -* ]]; then
                COMPREPLY=( $(compgen -W "-p --persistence -y --yes -h --help" -- "$cur") )
            else
                _filedir
            fi
            ;;
        list)
            COMPREPLY=( $(compgen -W "-h --help" -- "$cur") )
            ;;
    esac
}
complete -F _synex_mkboot synex-mkboot
