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

Enable custom commands to have custom autocompletion #5783

Closed
1 task done
GuySartorelli opened this issue Feb 5, 2024 · 2 comments
Closed
1 task done

Enable custom commands to have custom autocompletion #5783

GuySartorelli opened this issue Feb 5, 2024 · 2 comments

Comments

@GuySartorelli
Copy link
Collaborator

GuySartorelli commented Feb 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem?

Currently there's no autocompletion for custom command argumentss. This means users have to constantly check help to see what arguments are available to them.

Describe your solution

There are two kinds of autocompletion at play:

  1. static completion - i.e. specific values that can be used for arguments which are known ahead of time
  2. dynamic completion - i.e. values that are evaluated at runtime, most likely through a bash function

The static completion would be really easy to add via a new annotation, e.g. the annotation for ddev xdebug might look like this:

## AutocompleteTerms: ["on","off","enable","disable","toggle","status"]

Dynamic completion would require a bash script that's separate to the main command script.
I recommend having a autocompletion subdirectory inside each service command dir. Any script inside the autocompletion directory which matches the name of a command will be used as the script to call for autocompletions.

e.g.

~/.ddev/commands/
├─ host/
   ├─ autocompletion/
      └─ script2
   ├─ script1
   ├─ script2
   └─ ...
├─ web/
   ├─ autocompletion/
      ├─ nvm
      └─ ...
   ├─ script1
   ├─ nvm
   └─ ...
└─ ...

Above, when setting up the nvm command, the ~/.ddev/commands/web/autocompletion/nvm script will be used for any autocompletions.

Describe alternatives

No response

Additional context

Static Flag autocompletion is already provided. We could look at doing dynamic flag autocompletion as well (e.g. completion for values that can be passed to flags).

Any discussion about that should be included in this issue, because it will likely affect the way this is implemented. Forking that off as a separate conversation would risk implementing autocompletion for args in a way that makes it difficult to introduce dynamic flag autocompletion without breaking changes.

@GuySartorelli
Copy link
Collaborator Author

I've created a POC PR to show a) that this is possible and b) what an implementation of this might look like: #5785

@GuySartorelli
Copy link
Collaborator Author

Note that I mention flag completion here - but it turns out that can be handled in the same script that handles arg completion. If the user types ddev my-command --<tab>, the -- will be included in the args passed to the autocomplete script, and the script can return suggested flags (prefixed with --).

@rfay rfay closed this as completed in 1be7e65 Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant