Skip to content

Commit e0cdf62

Browse files
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 <jeffreyaven@users.noreply.github.com>
1 parent ce896e0 commit e0cdf62

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,44 @@ Use the `--help` option to see more information about the commands and options a
237237
stackql-deploy --help
238238
```
239239
240+
### Tab Completion
241+
242+
**stackql-deploy** supports tab completion for commands and options across multiple shells. To enable tab completion:
243+
244+
#### Bash
245+
Add the following to your `~/.bashrc`:
246+
```bash
247+
eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)"
248+
```
249+
250+
#### Zsh
251+
Add the following to your `~/.zshrc`:
252+
```bash
253+
eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)"
254+
```
255+
256+
#### Fish
257+
Add the following to your `~/.config/fish/config.fish`:
258+
```bash
259+
eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy)
260+
```
261+
262+
#### PowerShell
263+
Add the following to your PowerShell profile:
264+
```powershell
265+
Invoke-Expression (& stackql-deploy completion powershell)
266+
```
267+
268+
> **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.
269+
270+
You can also generate shell-specific completion scripts using:
271+
```bash
272+
stackql-deploy completion bash # for bash
273+
stackql-deploy completion zsh # for zsh
274+
stackql-deploy completion fish # for fish
275+
stackql-deploy completion powershell # for PowerShell
276+
```
277+
240278
## Building and Testing Locally
241279
242280
To get started with **stackql-deploy**, install it locally using pip:

stackql_deploy/cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,49 @@ def upgrade(ctx):
381381
stackql.upgrade()
382382

383383

384+
#
385+
# completion command
386+
#
387+
388+
@cli.command()
389+
@click.argument('shell', type=click.Choice(['bash', 'zsh', 'fish', 'powershell'], case_sensitive=False))
390+
def completion(shell):
391+
"""Generate shell completion script for the specified shell.
392+
393+
To enable tab completion, run one of the following:
394+
395+
For bash (add to ~/.bashrc):
396+
eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)"
397+
398+
For zsh (add to ~/.zshrc):
399+
eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)"
400+
401+
For fish (add to ~/.config/fish/config.fish):
402+
eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy)
403+
404+
For PowerShell (add to $PROFILE):
405+
Invoke-Expression (& stackql-deploy completion powershell)
406+
"""
407+
shell_lower = shell.lower()
408+
409+
if shell_lower == 'bash':
410+
click.echo('eval "$(_STACKQL_DEPLOY_COMPLETE=bash_source stackql-deploy)"')
411+
elif shell_lower == 'zsh':
412+
click.echo('eval "$(_STACKQL_DEPLOY_COMPLETE=zsh_source stackql-deploy)"')
413+
elif shell_lower == 'fish':
414+
click.echo('eval (env _STACKQL_DEPLOY_COMPLETE=fish_source stackql-deploy)')
415+
elif shell_lower == 'powershell':
416+
click.echo('Register-ArgumentCompleter -Native -CommandName stackql-deploy -ScriptBlock {')
417+
click.echo(' param($wordToComplete, $commandAst, $cursorPosition)')
418+
click.echo(' $env:_STACKQL_DEPLOY_COMPLETE = "complete"')
419+
click.echo(' $env:COMP_WORDS = $commandAst.ToString()')
420+
click.echo(' $env:COMP_CWORD = $cursorPosition')
421+
click.echo(' stackql-deploy | ForEach-Object {')
422+
click.echo(' [System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_)')
423+
click.echo(' }')
424+
click.echo('}')
425+
426+
384427
#
385428
# init command
386429
#
@@ -458,6 +501,7 @@ def init(stack_name, provider):
458501
cli.add_command(init)
459502
cli.add_command(upgrade)
460503
cli.add_command(shell)
504+
cli.add_command(completion)
461505

462506
if __name__ == '__main__':
463507
cli()

0 commit comments

Comments
 (0)