[Python] Shell completion dependent on arguments already provided

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I was wondering if it's possible using Click 8 to implement shell completion may depend on commands, options, and arguments that have already been specified earlier on the command line. I see that ctx.params does not include them, however. In any case, consider the following example.

    ./foo.py --global-opt foo my_command --command-opt <TAB>


    I am wondering how to have tab completion for --command-opt depend on the value of --global-opt (a callback, i.e. global, option). Ideally, one could do the usual processing for --global-opt first, before doing shell completion for --command-opt.

    In fact, I was told by one of the maintainers that this is possible, but he failed to explain how. Any advice or example would be appreciated.

    Continue reading...

Compartilhe esta Página