Coverage for src/workstack/cli/commands/completion.py: 38%
34 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-19 09:31 -0400
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-19 09:31 -0400
1import os
2import shutil
3import subprocess
4import sys
6import click
9@click.group("completion")
10def completion_group() -> None:
11 """Generate shell completion scripts."""
14@completion_group.command("bash")
15def completion_bash() -> None:
16 """Generate bash completion script.
18 \b
19 For automatic setup of both completion and auto-activation:
20 workstack init --shell
22 \b
23 To load completions in your current shell session:
24 source <(workstack completion bash)
26 \b
27 To load completions permanently, add to your ~/.bashrc:
28 echo 'source <(workstack completion bash)' >> ~/.bashrc
30 \b
31 Alternatively, you can save the completion script to bash_completion.d:
32 workstack completion bash > /usr/local/etc/bash_completion.d/workstack
34 \b
35 You will need to start a new shell for this setup to take effect.
36 """
37 # Find the workstack executable
38 workstack_exe = shutil.which("workstack")
39 if not workstack_exe:
40 # Fallback to current Python + module
41 workstack_exe = sys.argv[0]
43 env = os.environ.copy()
44 env["_WORKSTACK_COMPLETE"] = "bash_source"
45 result = subprocess.run([workstack_exe], env=env, capture_output=True, text=True)
46 click.echo(result.stdout, nl=False)
49@completion_group.command("zsh")
50def completion_zsh() -> None:
51 """Generate zsh completion script.
53 \b
54 For automatic setup of both completion and auto-activation:
55 workstack init --shell
57 \b
58 To load completions in your current shell session:
59 source <(workstack completion zsh)
61 \b
62 To load completions permanently, add to your ~/.zshrc:
63 echo 'source <(workstack completion zsh)' >> ~/.zshrc
65 \b
66 Note: Make sure compinit is called in your ~/.zshrc after loading completions.
68 \b
69 You will need to start a new shell for this setup to take effect.
70 """
71 # Find the workstack executable
72 workstack_exe = shutil.which("workstack")
73 if not workstack_exe:
74 # Fallback to current Python + module
75 workstack_exe = sys.argv[0]
77 env = os.environ.copy()
78 env["_WORKSTACK_COMPLETE"] = "zsh_source"
79 result = subprocess.run([workstack_exe], env=env, capture_output=True, text=True)
80 click.echo(result.stdout, nl=False)
83@completion_group.command("fish")
84def completion_fish() -> None:
85 """Generate fish completion script.
87 \b
88 For automatic setup of both completion and auto-activation:
89 workstack init --shell
91 \b
92 To load completions in your current shell session:
93 workstack completion fish | source
95 \b
96 To load completions permanently:
97 mkdir -p ~/.config/fish/completions && \\
98 workstack completion fish > ~/.config/fish/completions/workstack.fish
100 \b
101 You will need to start a new shell for this setup to take effect.
102 """
103 # Find the workstack executable
104 workstack_exe = shutil.which("workstack")
105 if not workstack_exe:
106 # Fallback to current Python + module
107 workstack_exe = sys.argv[0]
109 env = os.environ.copy()
110 env["_WORKSTACK_COMPLETE"] = "fish_source"
111 result = subprocess.run([workstack_exe], env=env, capture_output=True, text=True)
112 click.echo(result.stdout, nl=False)