wasmCloud / wasmCloud

wasmCloud is an open source Cloud Native Computing Foundation (CNCF) project that enables teams to build, manage, and scale polyglot apps across any cloud, K8s, or edge.
https://wasmcloud.com
Apache License 2.0
1.49k stars 145 forks source link

[FEATURE] Use clap_autocomplete for control interface + app commands #3258

Open brooksmtownsend opened 3 weeks ago

brooksmtownsend commented 3 weeks ago

Affected project(s)

Is your feature request related to a problem? Please describe.

I find it pretty frustrating that when using wash I can't tab autocomplete to fill in easily searchable values. For example, if I want to undeploy an application named rust-hello-world, and I have another app called foobar, I can't do the following to avoid typing in the whole app name (or realistically, copy/pasting it):

wash app undeploy rust<TAB>

Same thing with referencing control interface values:

wash stop component foo<TAB>
wash stop host NASD<TAB>

Describe the solution you'd like

The clap_autocomplete crate is a great way to do this since we already use clap. In response to a event for an argument where there is an existing entity in the lattice, we should be able to query for it.

For example, after typing wash stop host <TAB>, we should be able to use the clap autocomplete hook to query the lattice for hosts, and return a set of host IDs.

Describe alternatives you've considered

There are many different commands this could be used for in wash, but to start the ctl + app subcommands will be the most impactful.

Additional context

Note that we already have autocompletion for the wash subcommands, I specifically want to add the feature here to autocomplete for arguments about existing resources in a wasmCloud cluster. The old command autocomplete should still work after we do this.

nm723 commented 3 weeks ago

Hi @brooksmtownsend ! I'd like to work on this issue, could you assign it to me?

lachieh commented 3 weeks ago

Thanks, @nm723!

Do you have an estimate as to when you would have this work ready for some initial feedback? Note that this is not a hard rule—we just like to get rough estimates up front so we can be helpful with checkins and scheduling.

nm723 commented 3 weeks ago

@lachieh Thanks for assigning it to me. I think it will take about a week, but I'm not totally sure yet. I'll let you know if there are any changes.

brooksmtownsend commented 3 weeks ago

Thanks @nm723 ! Please feel free to open a draft PR for initial feedback anytime 😄 Especially if you have questions

nm723 commented 2 weeks ago

Sorry @lachieh , I couldn’t find enough time this week, so it’s looking like I’ll need to finish it next week.

lachieh commented 2 weeks ago

No problems! Thanks for the update! If there's anything you need, be sure to ask!

nm723 commented 1 week ago

I tried clap_autocomplete, then I found out it is a simplification of creating completion files, by simply running <command> complete, which detects the shell and generates the file in the appropriate location. Therefore, I think it does not provide any hooks for dynamic actions. (Anyway, I found an error and created fix PR on it. )

I found this issue, and I think it's what we want to do. In the issue, there was an announcement that the initial version was released 2 months ago (docs). It looks like we need to enable the unstable-dynamic feature on clap_complete to use it, but is it okay to use an unstable feature? @brooksmtownsend