Open tom10271 opened 1 year ago
Hi @tom10271, could you elaborate on what kind of autocomplete you mean for commands?
So far only zsh autocomplete implementation for space-separated commands supports flag value completion: https://github.com/oclif/plugin-autocomplete/releases/tag/2.1.0
zsh autocomplete for colon-separated commands doesn't support it yet but seems easy to add now.
Is there any interest in getting autocomplete for args that specify a known set of options?
Mainly to support autocomplete for values that supplied from users which can be resolved by calling callback, for example I have a git helper and it asks for branch name. I have solved my problem with commander.js and will not use oclif at this moment.
Ahh, I explored dynamic shell completion last year but wasn't able to implement it as I wasn't familiar with zsh/bash comp engine, should give it a try again.
we could add support for a new prop in non-boolean flags/command args to assign a function that returns an array of strings, then most of the work will be in each shell autocomplete implementation as it will need a way to call that function (that works for npm, installer and tarball installations).
I have dived deep into how autocomplete works recently. I might be able to create a doc explaining how things works and how to make it extensible by developers.
The libraries I am using are https://github.com/twolfson/commander-completion https://github.com/twolfson/line-info https://github.com/twolfson/completion
I think line-info and completion are useful for oclif, yet please noted that these libraries were developed 10 years ago and tbh the documents written are not easy to understand and I have spent a lot of hours on guessing how it actually works.
@tom10271 interesting, I'll take a look at that!
All of the shell completion code for oclif lives here: https://github.com/oclif/plugin-autocomplete/
I've spent the last month writing a new autocomplete implementation for zsh and have some ideas about how to make it work there. Haven't touched bash completion yet and will start working on support for PowerShell next week so hopefully will have more data to make this work on all shells.
See also dynamic completion in the Cobra framework: https://github.com/spf13/cobra/blob/main/shell_completions.md#dynamic-completion-of-nouns
This issue has been linked to a new work item: W-12549907