feat(cli): add prefix-based command matching and autocomplete module#644
feat(cli): add prefix-based command matching and autocomplete module#644shreejaykurhade wants to merge 3 commits intoQuantConnect:masterfrom
Conversation
|
Interesting thank you @shreejaykurhade , we'll review and get back to you next week when MM's back. |
|
Sure |
Martin-Molinero
left a comment
There was a problem hiding this comment.
Hey @shreejaykurhade!
Thanks for the contribution 🙌
Overall I think it's promising, I'm not convinced installing files on the users machine is a good pattern for the autocomplete though, seems click has a dynamic way of doing this? Think we should double check what does click suggest as autocomplete approach and what are other popular libraries doing. Should a nice test suite too, there are no tests 😱 .
Also I think ideally it's enabled by default? Again would double check what click and popular libraries suggest, finally I would double check performance implications though, what's the overhead cost we might determine not worth enabling by default
| elif len(matches) == 1: | ||
| return super().get_command(ctx, matches[0]) | ||
|
|
||
| ctx.fail(f"Too many matches: {', '.join(sorted(matches))}") |
There was a problem hiding this comment.
Love it! Seems to me this could be it's own PR with it's own tests @shreejaykurhade
| temp_manager = container.temp_manager | ||
| if temp_manager.delete_temporary_directories_when_done: | ||
| temp_manager.delete_temporary_directories() | ||
| except click.exceptions.Exit as e: |
There was a problem hiding this comment.
For speed we avoid global imports like import click or even avoid imports completely unless required, see the except clause bellow where we import just what we need if we need it, should follow the pattern with Exit too
|
@Martin-Molinero create and delete the cmd profile using "lean completion on" and "lean completion off"
The completion flow now follows Click’s native _LEAN_COMPLETE mechanism instead of installing scripts directly into profile files. Users can opt in by running lean completion --shell and evaluating the generated script in their shell. Changes
Examples
Tests Added test coverage for:
Verified with: |
GitHub Pull Request: Advanced Autocomplete & Shorthand Command Execution
Summary
This Pull Request introduces significant usability improvements to the Lean CLI. It implements Prefix-based Command Matching (allowing shorthand like
lean clinstead oflean cloud) and a Native Autocomplete Management Module that supports interactive, visual predictions in PowerShell and traditional completion in Bash/Zsh/Fish.Files Changed & Practical Reason
1.
lean/main.pyReason: To resolve "Silent Crashes" during automated tasks (like autocomplete script generation).
Excerpt:
Logic: Prevents Click's clean exit signals from being swallowed by the general exception handler and logged as errors.
2.
lean/components/util/click_aliased_command_group.pyReason: To enable the "Shorthand" feature where typing
lean clresolves and runslean cloud.Excerpt:
Logic: Overrides the standard command lookup. If no exact match is found, it performs a prefix search on all available subcommands.
3.
lean/commands/__init__.pyReason: Registering the new
autocompletecommand group to the main CLI.Excerpt:
4.
lean/commands/<group>/__init__.py(Multiple)Reason: Activating prefix-matching on individual command groups (Cloud, Config, Data, etc.).
Excerpt:
5.
lean/commands/autocomplete.py(Full Module)Reason: A comprehensive management tool for shell-native autocomplete integration.
Key Features:
PSReadLine.enableanddisablecommands to modify$PROFILEor.bashrc.[FULL CODE Logic Snippet]
Verification
lean clsuccessfully executeslean cloud.lean clo+Tabperforms ghost-text prediction.enablecommand successfully injects code into PowerShell profile.Exitcodes are handled cleanly without logging errors.Autocomplete Visual Behavior
🔹 Top-Level Command List
Typing
leanfollowed by a Tab will now trigger a full scan of the command tree and present a visual menu of every available root-level command (e.g.,backtest,cloud,config,data).🔹 Prefix Matching & Expansion
Typing a partial command such as
lean cland pressing Tab will:cl.cloud).🔹 Deep-Level Discovery
The behavior is recursive. Typing
lean cloud+ Tab will correctly discover and list only the sub-commands relevant to the cloud group (pull,push,backtest, etc.).