Closed XReaper95 closed 4 years ago
AFAICU, shell completion is made by communicating the relevant information on stdout between the python program and the shell.
The callback is called when the completion is triggered. I suggest you use stderr to display an error. Actually, you would suggest to generally use stderr to deal with error messages.
Also, IIUC, ctx.resilient_parsing is True during the completion and False during the « normal » execution. You might want to use this value to change the behavior during the completion.
@Konubinix Thank you so much for your help! , ctx.resilient_parsing was exactly what I needed, I read about it in the documentation but wasn't sure how to use it, until now. I will also take your suggestion regarding the stderr errors. My problem has been solved so I'm closing the issue.
Luis Ernesto Del Toro Peña notifications@github.com writes:
@Konubinix Thank you so much for your help! , ctx.resilient_parsing was exactly what I needed, I read about it in the documentation but wasn't sure how to use it, until now. I will also take your suggestion regarding the stderr errors. My problem has been solved so I'm closing the issue.
I am glad to know it was helpful :-).
-- Konubinix GPG Key : 7439106A Fingerprint: 5993 BE7A DA65 E2D9 06CE 5C36 75D2 3CED 7439 106A
Hi, so in my CLI, I have some callbacks with complex functionality. One of them checks for a specific file in the current directory, and exits with an error printed to sys.stdout. The problem is that the shell tries to evaluate that printed string. I am not sure what this is happening, don't know much about shells and autocompletion. I'm using ZSH, and you can easily replicate this error in one of the examples of this repository.
At examples/click-completion-callback, line 15, add this print statement:
If you try to complete this with TAB
cli echo <TAB>'
, it produces this error