###-begin-{{app_name}}-completions-###
#
# codefresh command completion script
#
# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
#    or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
#
_codefresh_completions()
{
    local cur args type_list

    cur="${COMP_WORDS[COMP_CWORD]}"
    args=("${COMP_WORDS[@]}")

    # ask codefresh to generate completions.
    type_list=$(codefresh --get-yargs-completions "${args[@]}")

    if [[ ${type_list} == '__files_completion__' ]]; then
        _filedir "@(yaml|yml|json)"
    else
        COMPREPLY=( $(compgen -W "${type_list}" -- ${cur}) )
    fi

    return 0
}
complete -F _codefresh_completions {{app_name}}
###-end-{{app_name}}-completions-###
