NatLibFi / Annif

Annif is a multi-algorithm automated subject indexing tool for libraries, archives and museums.
https://annif.org
Other
195 stars 41 forks source link

CLI command completions #684

Closed juhoinkinen closed 1 year ago

juhoinkinen commented 1 year ago

Click provides support for tab completion in different shells. In the case of Annif, Click documentation instructs to use this to register the autocompletion function (and to add it to ~/.bashrc):

eval "$(_ANNIF_COMPLETE=bash_source annif)"

We could add this to installation instructions. Or even add an Annif command to generate the function, like in helm CLI.

The completion is a bit laggy but usable. Apparently the cli.py module is run for each tab press, and the imports there take most of the time.

The default completions work for "command names, option names, and values for choice, file, and path parameter types". In the case of Annif it would be nice to have completions also for project-ids, which could be accomplished using a class with shell_complete() method or just a helper function: in either case the method/function would need to read the project ids from the configuration file, but (preferably) not via registry.get_projects() because then imports of backend dependencies would make the completion unnecessarily slow.

osma commented 1 year ago

Sounds good, and this is another reason why optimizing startup performance is important (which generally means using lazy imports of some kind). Some of this has already been done (#514, #544, #563) but I think another round of optimization should be done after the refactoring in #681.

juhoinkinen commented 1 year ago

Closed by the linked issue.