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

Support for CLI command completions #693

Closed juhoinkinen closed 1 year ago

juhoinkinen commented 1 year ago

Adds support for tab-key completions for commands, options and project id and vocabulary id parameters via Click mechanism.

A user needs to enable the support as instructed in README.md, i.e. by sourcing the completion script, either manually for every terminal session or automatically for all new sessions by the sourcing the script in a shell startup file (instructed to use .bashrc).

To produce the completion script the annif completion CLI command is added. This seems to be the standard way that many CLI tools use: pip, dvc, helm.

Implements #684.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 98.48% and project coverage change: +0.01 :tada:

Comparison is base (c6daf56) 99.61% compared to head (35bc222) 99.63%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #693 +/- ## ========================================== + Coverage 99.61% 99.63% +0.01% ========================================== Files 89 89 Lines 6166 6222 +56 ========================================== + Hits 6142 6199 +57 + Misses 24 23 -1 ``` | [Impacted Files](https://codecov.io/gh/NatLibFi/Annif/pull/693?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi) | Coverage Δ | | |---|---|---| | [annif/cli\_util.py](https://codecov.io/gh/NatLibFi/Annif/pull/693?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi#diff-YW5uaWYvY2xpX3V0aWwucHk=) | `98.87% <90.90%> (-1.13%)` | :arrow_down: | | [annif/cli.py](https://codecov.io/gh/NatLibFi/Annif/pull/693?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi#diff-YW5uaWYvY2xpLnB5) | `99.64% <100.00%> (+0.01%)` | :arrow_up: | | [tests/test\_cli.py](https://codecov.io/gh/NatLibFi/Annif/pull/693?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi#diff-dGVzdHMvdGVzdF9jbGkucHk=) | `100.00% <100.00%> (ø)` | | ... and [1 file with indirect coverage changes](https://codecov.io/gh/NatLibFi/Annif/pull/693/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi) Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NatLibFi)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

juhoinkinen commented 1 year ago

The completion response is not very instantaneous but quite usable. On my laptop annif --help and annif --version take 0.6-0.7 s, but I think the completion response is a bit faster.

I tried to optimize startup speed by moving some import statements into functions in cli.py and elsewhere. This cut annif --version time in half but did not affect annif --help and seemed not to affect completion response time. :(

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

juhoinkinen commented 1 year ago

The completion response is not very instantaneous but quite usable. On my laptop annif --help and annif --version take 0.6-0.7 s, but I think the completion response is a bit faster.

I tried to optimize startup speed by moving some import statements into functions in cli.py and elsewhere. This cut annif --version time in half but did not affect annif --help and seemed not to affect completion response time. :(

The response time of completions will be improved by #696 to ~0.3 seconds or slightly less.