-
Notifications
You must be signed in to change notification settings - Fork 160
feat(cli): add prefix-based command matching and autocomplete module #644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shreejaykurhade
wants to merge
3
commits into
QuantConnect:master
Choose a base branch
from
shreejaykurhade:feat/autocomplete-aliasing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d5cb8a7
feat(cli): add prefix-based command matching and autocomplete module
shreejaykurhade ca34013
feat(cli): add Click-native shell completion and prefix-based command…
shreejaykurhade 0883232
feat(cli): add Click-native shell completion with simple on/off commands
shreejaykurhade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
| # Lean CLI v1.0. Copyright 2021 QuantConnect Corporation. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from click import Choice, Context, echo, group, option, pass_context | ||
|
|
||
| from lean.components.util.click_aliased_command_group import AliasedCommandGroup | ||
| from lean.components.util.click_shell_completion import get_completion_script, install_completion, uninstall_completion | ||
|
|
||
|
|
||
| SHELL_OPTION = option("--shell", | ||
| "-s", | ||
| type=Choice(["powershell", "bash", "zsh", "fish"], case_sensitive=False), | ||
| default=None, | ||
| help="Target shell. Auto-detected if not specified.") | ||
|
|
||
|
|
||
| @group(cls=AliasedCommandGroup, invoke_without_command=True) | ||
| @SHELL_OPTION | ||
| @pass_context | ||
| def completion(ctx: Context, shell: Optional[str]) -> None: | ||
| """Print the native shell completion script for your shell. | ||
|
|
||
| \b | ||
| PowerShell (current session): | ||
| lean completion --shell powershell | Out-String | Invoke-Expression | ||
|
|
||
| \b | ||
| Bash or Zsh (current session): | ||
| eval "$(lean completion --shell bash)" | ||
|
|
||
| \b | ||
| Fish (current session): | ||
| lean completion --shell fish | source | ||
| """ | ||
| if ctx.invoked_subcommand is None: | ||
| echo(get_completion_script(shell)) | ||
|
|
||
|
|
||
| @completion.command(name="show", help="Print the native shell completion script for your shell") | ||
| @SHELL_OPTION | ||
| def show(shell: Optional[str]) -> None: | ||
| echo(get_completion_script(shell)) | ||
|
|
||
|
|
||
| @completion.command(name="on", help="Enable shell completion in your shell profile") | ||
| @SHELL_OPTION | ||
| def on(shell: Optional[str]) -> None: | ||
| profile_path = install_completion(shell) | ||
| echo(f"Enabled shell completion in {profile_path}") | ||
| echo("Open a new terminal session for the change to take effect.") | ||
|
|
||
|
|
||
| @completion.command(name="off", help="Disable shell completion in your shell profile") | ||
| @SHELL_OPTION | ||
| def off(shell: Optional[str]) -> None: | ||
| profile_path, removed = uninstall_completion(shell) | ||
|
|
||
| if removed: | ||
| echo(f"Disabled shell completion in {profile_path}") | ||
| echo("Open a new terminal session for the change to take effect.") | ||
| else: | ||
| echo(f"Shell completion was not enabled in {profile_path}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.