# fleetctl(1) bash-completion
# See "Programmable Completion" section in bash(1).

_fleetctl() {
    local _fleetctl_global_options='--ssh-username --strict-host-key-checking --tunnel --debug --ca-file --cert-file --key-file --help'
    local _fleetctl_commands='cat destroy fd-forward help journal list-machines list-unit-files list-units load ssh start status stop submit unload version'
    local cur prev
    COMPREPLY=()
    _get_comp_words_by_ref -n : cur prev

    if [[ $COMP_CWORD -eq 1 ]] ; then
        COMPREPLY=( $( compgen -W "${_fleetctl_global_options} ${_fleetctl_commands}" -- $cur ) )
    else
        case $prev in
           cat|destroy|journal|load|start|status|stop)
                COMPREPLY=( $( compgen -W "$(fleetctl list-units | awk '{print $1}' | grep -v UNIT)" -- $cur ) )
            ;;
        esac
    fi
}
complete -F _fleetctl fleetctl
