Skip to content
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

Support values autocomplete in command and option #426

Open
tom10271 opened this issue Feb 15, 2023 · 6 comments
Open

Support values autocomplete in command and option #426

tom10271 opened this issue Feb 15, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@tom10271
Copy link

No description provided.

@git2gus
Copy link

git2gus bot commented Feb 15, 2023

This issue has been linked to a new work item: W-12549907

@cristiand391
Copy link
Member

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?

@tom10271
Copy link
Author

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.

@cristiand391
Copy link
Member

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).

@tom10271
Copy link
Author

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.

@cristiand391
Copy link
Member

@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

@mdonnalley mdonnalley added enhancement New feature or request and removed enhancement labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants