Skip to content

Commit 6c11a85

Browse files
authored
Merge pull request #66 from stackql/claude/issue-65-20251011-0049
feat: add tab completion support for CLI commands
2 parents ce896e0 + 7cdd45b commit 6c11a85

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,47 @@ def upgrade(ctx):
381381
stackql.upgrade()
382382

383383

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

462504
if __name__ == '__main__':
463505
cli()

0 commit comments

Comments
 (0)