athena-framework / athena

An ecosystem of reusable, independent components
https://athenaframework.org
MIT License
211 stars 17 forks source link

Console tab-completion #294

Closed Blacksmoke16 closed 1 year ago

Blacksmoke16 commented 1 year ago

Implements command tab completion by leveraging the shell's built in completion features. Currently only bash is supported, but fish and zsh can/will be added in another PR. Command and option names are supported out of the box. Option/argument values can be defined by using the new suggested_values option when adding arguments/options which accepts either an Enumerable(String) or a block that should return an Array(String) if additional filtering is desired. The #complete method may also be overridden for more complex usages.

This functionality does require sourcing/placing a generated file in a location where you shell is able to read it. E.g. sourced within ~/.bashrc or placed within /etc/bash_completion.d/. This is a one-time setup, so not too big of a deal.

This can be done via the completion command that is bundled in with all console applications. E.g. ./console completion > completion.sh. Run ./console help completion formore information.

The name of the binary used to generate the script is important. In this case, completion.sh would handle auto completion for a binary called console, but not one called something else.

The completion script also is required to run with real binaries, not via like crystal run src/console.cr -- completion.

Resolves #293

paulocoghi commented 1 year ago

Wow! Incredible!

Blacksmoke16 commented 1 year ago

@paulocoghi Is still some work to do (mainly adding the other shells and augmenting existing commands), but feel free to try it out and let me know if you have any issues/suggestions.

paulocoghi commented 1 year ago

I will try it and let you know!