-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give instructions to user with zero possible completions #70
Comments
I think this might be a bit difficult, as it can be complicated to implement using native shell complements, and I haven't seen any examples calling scripts in other languages. |
I don't think it is difficult. The documentation is missing how to implement a completer that runs a script. Having this clear, take for example that when completing it would run |
Despite that, I really haven't seen any examples, at least in zsh completion, calling scripts in other languages as action, which involves how to tell the current command line state and then pass it back to the script, etc. It's hard for people who are not particularly familiar with each shell system completion to do that, which is probably why argcomplete only supports bash at the moment. In addition, I think checking for legal variables on each input can be slow in a complex CLI, especially if I use a plugin like zsh-autocomplete that automatically generates completions. Speed is also a big problem for me when using argcomplete. |
The motivation for this feature is precisely to allow implementing automatic generation of completions. In particular, automatic generation from type hints. Also note that it is not strictly necessary to call another script for this feature to be useful. So there would be no issues regarding speed. For the example above the completions could be:
The shell specific logic should be part of shtab, such that people using it don't need to worry about these details. How to tell shtab to do this could be like: parser.add_argument('--int', type=int).complete = shtab.instructions("expected type int") This would be if someone using argparse would want to do this. But my goal is that people using jsonargparse would have no need to specify |
Looks like 2 separate issues to me. custom completionAssuming you have this: cli.py list-valid-ints # prints a finite (!) list of options
cli.py --int <int> # should tab-complete based on the above Then see https://github.com/iterative/dvc/blob/main/dvc/cli/completion.py which has this pattern. The docs indirectly mention this (https://docs.iterative.ai/shtab/use/#library-usage -> https://github.com/iterative/dvc/blob/main/dvc/commands/completion.py). PRs/suggestions (modifying the docs source) to make it clearer are welcome. type validationHowever if you have this: cli.py --int <int> # tab (rather than enter) should perform validation I feel that's probably out of scope? Isn't the whole point of |
The point of a tool like As I said in my previous comment, there is no need for value validation for the proposed feature to be useful. So this github issue can focus on giving static instructions with zero possible completions.
Being required to implement shell specific preambles is not developer friendly and is a big amount of boilerplate if a similar feature is to be added to different projects. What this github issue proposes is to add to Regarding the documentation, it is quite far away from explaining about preambles and shell specific code. Regardless, I don't think this is about improving documentation of the current
It is not clear to me what is the behavior with this. Let me give a different example. The behavior can be shell dependent, so assume the following is for bash. Assume an argument is added like action = parser.add_argument('--lottery-numbers', type=int, nargs=5) Note that there is no parser validation regarding the range of numbers. And since they are numbers, there is nothing that can be completed, i.e. the command written by the user won't be extended. With the proposed feature, a developer could do action.complete = shtab.instructions("give five numbers between 1 and 56") The tab behavior would be the following.
Note that the different prompts A final note. Have in mind what I wrote at the end of the description in #68. My idea is that later on the action = parser.add_argument("--style", type=str)
action.complete = [
shtab.path_completer(["*.jpg"]),
shtab.instructions("path to the image with the target style to apply"),
] In this case |
I have now implemented automatic |
Thanks! Had a brief look; your implementation seems to do: Seems pretty nifty; though unsure how easy it would be to implement generic versions in |
A feature that jsonargparse+argcomplete supports is the print of help when there are zero possible completions. It would be great if the same feature can be implemented for shtab.
To explain what this feature does, the most simple case is an int argument. The value given to the argument could be already or not yet a valid int. In both cases nothing can be completed, only a message can be given to help the user. The following code snippet and behavior in the shell can illustrate this a bit better:
Some details from when this was implemented for argcomplete can be seen in kislyuk/argcomplete#328.
It is not clear to me how this could be implemented for shtab. Since there can be any number of data types that would have this behavior, this probably should be done with a completer that runs a python script. This is suggested in the last point in comment omni-us/jsonargparse#108 (comment). However, neither the documentation of shtab or the customcomplete.py example make it clear how to do something like this.
The text was updated successfully, but these errors were encountered: