From e0cdf628583a1952986189ea29236a06dcec9991 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 00:51:48 +0000 Subject: [PATCH 1/3] feat: add tab completion support for CLI commands - Add new 'completion' command to generate shell completion scripts - Support bash, zsh, fish, and PowerShell shells - Leverage Click's built-in shell completion functionality - Update README with detailed setup instructions for each shell - Enable tab completion for subcommands and flags across all shells Resolves #65 Co-authored-by: Jeffrey Aven --- README.md | 38 +++++++++++++++++++++++++++++++++++++ stackql_deploy/cli.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/README.md b/README.md index 15065dd..90b081a 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,44 @@ Use the `--help` option to see more information about the commands and options a stackql-deploy --help ``` +### Tab Completion + +**stackql-deploy** supports tab completion for commands and options across multiple shells. To enable tab completion: + +#### Bash +Add the following to your `~/.bashrc`: +```bash +eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)" +``` + +#### Zsh +Add the following to your `~/.zshrc`: +```bash +eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)" +``` + +#### Fish +Add the following to your `~/.config/fish/config.fish`: +```bash +eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy) +``` + +#### PowerShell +Add the following to your PowerShell profile: +```powershell +Invoke-Expression (& stackql-deploy completion powershell) +``` + +> **Note:** After adding the completion configuration to your shell's configuration file, restart your terminal or source the configuration file for the changes to take effect. + +You can also generate shell-specific completion scripts using: +```bash +stackql-deploy completion bash # for bash +stackql-deploy completion zsh # for zsh +stackql-deploy completion fish # for fish +stackql-deploy completion powershell # for PowerShell +``` + ## Building and Testing Locally To get started with **stackql-deploy**, install it locally using pip: diff --git a/stackql_deploy/cli.py b/stackql_deploy/cli.py index b1ba854..a813a6f 100644 --- a/stackql_deploy/cli.py +++ b/stackql_deploy/cli.py @@ -381,6 +381,49 @@ def upgrade(ctx): stackql.upgrade() +# +# completion command +# + +@cli.command() +@click.argument('shell', type=click.Choice(['bash', 'zsh', 'fish', 'powershell'], case_sensitive=False)) +def completion(shell): + """Generate shell completion script for the specified shell. + + To enable tab completion, run one of the following: + + For bash (add to ~/.bashrc): + eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)" + + For zsh (add to ~/.zshrc): + eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)" + + For fish (add to ~/.config/fish/config.fish): + eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy) + + For PowerShell (add to $PROFILE): + Invoke-Expression (& stackql-deploy completion powershell) + """ + shell_lower = shell.lower() + + if shell_lower == 'bash': + click.echo('eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)"') + elif shell_lower == 'zsh': + click.echo('eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)"') + elif shell_lower == 'fish': + click.echo('eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy)') + elif shell_lower == 'powershell': + click.echo('Register-ArgumentCompleter -Native -CommandName stackql-deploy -ScriptBlock {') + click.echo(' param($wordToComplete, $commandAst, $cursorPosition)') + click.echo(' $env:_STACKQL_DEPLOY_COMPLETE = "complete"') + click.echo(' $env:COMP_WORDS = $commandAst.ToString()') + click.echo(' $env:COMP_CWORD = $cursorPosition') + click.echo(' stackql-deploy | ForEach-Object {') + click.echo(' [System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_)') + click.echo(' }') + click.echo('}') + + # # init command # @@ -458,6 +501,7 @@ def init(stack_name, provider): cli.add_command(init) cli.add_command(upgrade) cli.add_command(shell) +cli.add_command(completion) if __name__ == '__main__': cli() From 05690c33f5c12769479be08b70ac01aa01fa92c2 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 01:09:57 +0000 Subject: [PATCH 2/3] fix: break long line in completion command to meet ruff linting requirements Co-authored-by: Jeffrey Aven --- stackql_deploy/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stackql_deploy/cli.py b/stackql_deploy/cli.py index a813a6f..c123a92 100644 --- a/stackql_deploy/cli.py +++ b/stackql_deploy/cli.py @@ -386,7 +386,10 @@ def upgrade(ctx): # @cli.command() -@click.argument('shell', type=click.Choice(['bash', 'zsh', 'fish', 'powershell'], case_sensitive=False)) +@click.argument( + 'shell', + type=click.Choice(['bash', 'zsh', 'fish', 'powershell'], case_sensitive=False) +) def completion(shell): """Generate shell completion script for the specified shell. From 7cdd45b5e66ff90e466b2d9e9abebc98c6ec37b8 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Sat, 11 Oct 2025 01:47:11 +0000 Subject: [PATCH 3/3] fixed linting errors --- stackql_deploy/cli.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/stackql_deploy/cli.py b/stackql_deploy/cli.py index c123a92..683b5f0 100644 --- a/stackql_deploy/cli.py +++ b/stackql_deploy/cli.py @@ -387,28 +387,23 @@ def upgrade(ctx): @cli.command() @click.argument( - 'shell', + 'shell', type=click.Choice(['bash', 'zsh', 'fish', 'powershell'], case_sensitive=False) ) def completion(shell): """Generate shell completion script for the specified shell. - To enable tab completion, run one of the following: - For bash (add to ~/.bashrc): eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)" - For zsh (add to ~/.zshrc): eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)" - For fish (add to ~/.config/fish/config.fish): eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy) - For PowerShell (add to $PROFILE): Invoke-Expression (& stackql-deploy completion powershell) """ shell_lower = shell.lower() - + if shell_lower == 'bash': click.echo('eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)"') elif shell_lower == 'zsh':