-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add autocompletion for target orgs #620
Comments
@gilgourevitch This is an awesome idea 🏆 We definitely want to support this for Ideally, plugin-autocomplete would be able to merge together various autocomplete scripts. So, for instance, That feature, unfortunately, doesn't exist yet. I'm going to put this on our backlog so we can prioritize it |
This issue has been linked to a new work item: W-15022864 |
Hello @mdonnalley , and thank you for your feedback. I understand the concept. Do you already have an idea of the future code structure and how the custom scripts could be passed to the autocomplete plugin ? Having this in mind, I could start developing a script for this use-case, or if I can help on the core code, do not hesitate. |
@gilgourevitch I don't have anything in mind for how this would actually be implemented - just a high level idea of the feature. @cristiand391 is our resident autocomplete guru so I would defer to him how to implement this |
Hey @gilgourevitch 👋🏼 I explored this a while ago but never fully implemented it, here's a few things that would be needed:
For the With those 2 you could get dynamic completions, it would work like this:
Alternative to This would be a bit tricky because it requires extracting the logic from code and calling it outside the "oclif" context but would be way faster. I did this in my fuzzy completion script for sf: _fzf_complete_sf() {
if [[ "$@" == "sf " || "$@" == "sf which " || "$@" == "sf help " ]]; then
local commands_file preview_command
commands_file="/Users/cdominguez/Library/Caches/sf/autocomplete/fzf-cmp/commands.json"
preview_command="jq --arg cmd {} -r '. as \$commands | map(.id == \$cmd) | index(true) | \$commands[.].summary' $commands_file"
_fzf_complete --reverse --preview "$preview_command" --preview-window wrap,down,1 --prompt="sf> " -- "$@" < <(
jq -r '.[] | .id' $commands_file
)
else
local comp=$(node /Users/cdominguez/.local/share/sf/node_modules/@cristiand391/sf-plugin-fzf-cmp/lib/shell-completion.js "$@")
_fzf_complete --select-1 --ansi --prompt="sf> " -- "$@" < <(
echo $comp
)
fi
}
_fzf_complete_sf_post() {
cut -f 1
} Considerations
As an example you can try the npm completion, it's way slower and I try to never use it.
Related:
it does org username completion and caching
I'm happy to answer any questions if you wanna give this a try :) |
I'm super interested in that as well, as we're building our own CLI at my current company on top of Oclif and not having dynamic completion reduces the value proposal of our CLI. Thanks @cristiand391 for the extensive notes. I'm not sure I get that one though:
My own CLI takes 150ms to execute "--help" end-to-end, and the "heroku" CLI, which has arguably a lot of commands, take 0.8s. I think it's not unreasonable to consider a dynamic completion can go over 1s, but I don't think that will take "a few seconds". I'm willing to spend some time on the topic, though my knowledge of oclif internals are limited. Let me know if there's some valuable work to start in that space. |
I was thinking more about completion that requires doing some HTTP requests, reading local files and similar should be fine. I saw the angular CLI puts a
for a POC I think you can go with points 1 & 2 mentioned in my comment above, a After that you will have to pick either zsh or powershell completion to test it (there's bash support too but it's has a few bugs and I'm not very familiar with it, we may rewrite it in the future to fix some bugs/bring it to feature parity with others). also check the resources linked in this PR: and also the GitHub CLI generated completion script, you can see there how it calls its own |
for anyone interested in this feature, I build a plugin to generate a carapace spec for any oclif CLI: You can use the exec macro to get dynamic completion: |
As a Salesforce user on multiple orgs, with multiple Sandboxes, the target org aliases and usernames are case-sensitive, and when the CLI is authenticated locally in multiple orgs, it become more difficult to find the correct alias.
Adding autocompletion for this flag could ease the usage of the CLI.
The text was updated successfully, but these errors were encountered: