pallets / click

Python composable command line interface toolkit
https://click.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
15.6k stars 1.4k forks source link

Documentation of Autocompletion #2013

Closed lapwat closed 3 years ago

lapwat commented 3 years ago

I think there is a mistake in the documentation:

https://click.palletsprojects.com/en/8.0.x/shell-completion/

_{PROG_NAME}_COMPLETE variable should be source_{shell} not {shell}_source

davidism commented 3 years ago

It's correct as-is. https://github.com/pallets/click/blob/ddcabdd4f22f438c0c963150b930d0d09b04dea7/src/click/shell_completion.py#L36

lapwat commented 3 years ago

Following documentation does not return the right content on my side.

_CCC_COMPLETE=bash_source ccc

Usage: ccc [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

_CCC_COMPLETE=source_bash ccc

_ccc_completion() {
    local IFS=$'
'
    COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
                   COMP_CWORD=$COMP_CWORD \
                   _CCC_COMPLETE=complete $1 ) )
    return 0
}

_ccc_completionetup() {
    local COMPLETION_OPTIONS=""
    local BASH_VERSION_ARR=(${BASH_VERSION//./ })
    # Only BASH version 4.4 and later have the nosort option.
    if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
        COMPLETION_OPTIONS="-o nosort"
    fi

    complete $COMPLETION_OPTIONS -F _ccc_completion ccc
}
taranlu-houzz commented 3 years ago

@lapwat I had the same issue. For me, it was due to my version of click not updating to the latest (expected) version. I use poetry and my pyproject.toml had click as click = "^7.1.2" from when I initially added the dep, but that means that it will not allow an update that would move click to version 8.x.x. If you have a similar situation, either re-add the dep, or directly modify the version specification in pyproject.toml.

lapwat commented 3 years ago

@taranlu-houzz Thanks for your answer. I installed click the day I opened the issue.

In my requirements I only have click so the latest version should be installed.

I will check which version is installed.