deepctl-cmd-completion 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ """Shell completion command for deepctl."""
@@ -0,0 +1,191 @@
1
+ """Shell completion command for deepctl."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from deepctl_core import AuthManager, BaseCommand, BaseResult, Config, DeepgramClient
10
+ from rich.console import Console
11
+
12
+ console = Console()
13
+
14
+ # Click derives the completion env var from the invocation name.
15
+ # Users call the CLI as "dg", so the var is _DG_COMPLETE.
16
+ _SHELLS: dict[str, dict[str, str]] = {
17
+ "bash": {
18
+ "eval_line": 'eval "$(_DG_COMPLETE=bash_source dg)"',
19
+ "profile": "~/.bashrc",
20
+ "check_marker": "_DG_COMPLETE=bash_source",
21
+ },
22
+ "zsh": {
23
+ "eval_line": 'eval "$(_DG_COMPLETE=zsh_source dg)"',
24
+ "profile": "~/.zshrc",
25
+ "check_marker": "_DG_COMPLETE=zsh_source",
26
+ },
27
+ "fish": {
28
+ "eval_line": "eval (env _DG_COMPLETE=fish_source dg)",
29
+ "profile": "~/.config/fish/config.fish",
30
+ "check_marker": "_DG_COMPLETE=fish_source",
31
+ },
32
+ }
33
+
34
+
35
+ class CompletionResult(BaseResult):
36
+ """Return structure for the completion command."""
37
+
38
+ shell: str
39
+ eval_line: str
40
+ installed: bool = False
41
+ install_path: str | None = None
42
+
43
+
44
+ class CompletionCommand(BaseCommand):
45
+ """Generate shell completion scripts for dg."""
46
+
47
+ name = "completion"
48
+ help = "Generate shell completion script for bash, zsh, or fish"
49
+ short_help = "Generate shell completion"
50
+
51
+ requires_auth = False
52
+ requires_project = False
53
+ ci_friendly = True
54
+
55
+ examples = [
56
+ "dg completion",
57
+ "dg completion bash",
58
+ "dg completion zsh",
59
+ "dg completion fish",
60
+ 'eval "$(dg completion bash)"',
61
+ "dg completion zsh --install",
62
+ ]
63
+ agent_help = (
64
+ "Output the shell completion eval line for bash, zsh, or fish. "
65
+ "Source the output to enable tab-completion for all dg commands, "
66
+ "options, and arguments. Use --install to append to the shell profile "
67
+ "automatically. Shell is auto-detected from $SHELL if not specified."
68
+ )
69
+
70
+ def get_arguments(self) -> list[dict[str, Any]]:
71
+ """Get command arguments."""
72
+ return [
73
+ {
74
+ "name": "shell",
75
+ "help": "Shell type: bash, zsh, fish (auto-detected if omitted)",
76
+ "type": str,
77
+ "required": False,
78
+ "nargs": 1,
79
+ },
80
+ {
81
+ "names": ["--install"],
82
+ "help": "Append completion line to shell profile and exit",
83
+ "is_flag": True,
84
+ "is_option": True,
85
+ },
86
+ ]
87
+
88
+ def handle(
89
+ self,
90
+ config: Config,
91
+ auth_manager: AuthManager,
92
+ client: DeepgramClient,
93
+ **kwargs: Any,
94
+ ) -> Any:
95
+ """Handle completion command."""
96
+ shell = kwargs.get("shell") or self._detect_shell()
97
+ install = kwargs.get("install", False)
98
+
99
+ if shell not in _SHELLS:
100
+ console.print(
101
+ f"[red]Unknown shell:[/red] {shell!r}. Supported: {', '.join(_SHELLS)}"
102
+ )
103
+ return BaseResult(
104
+ status="error",
105
+ message=f"Unknown shell: {shell}",
106
+ )
107
+
108
+ cfg = _SHELLS[shell]
109
+ eval_line = cfg["eval_line"]
110
+ profile_path = Path(cfg["profile"]).expanduser()
111
+
112
+ if install:
113
+ return self._install(shell, eval_line, cfg["check_marker"], profile_path)
114
+
115
+ # Just print the eval line — users can pipe it directly:
116
+ # eval "$(dg completion bash)"
117
+ console.print(eval_line)
118
+ console.print(
119
+ f"\n[dim]Add the above line to {cfg['profile']},"
120
+ f" or run:[/dim]\n"
121
+ f" [bold]dg completion {shell} --install[/bold]",
122
+ highlight=False,
123
+ )
124
+
125
+ return CompletionResult(
126
+ status="success",
127
+ shell=shell,
128
+ eval_line=eval_line,
129
+ )
130
+
131
+ def _detect_shell(self) -> str:
132
+ """Detect the current shell from $SHELL."""
133
+ shell_bin = os.environ.get("SHELL", "")
134
+ if "zsh" in shell_bin:
135
+ return "zsh"
136
+ if "fish" in shell_bin:
137
+ return "fish"
138
+ return "bash"
139
+
140
+ def _install(
141
+ self,
142
+ shell: str,
143
+ eval_line: str,
144
+ check_marker: str,
145
+ profile_path: Path,
146
+ ) -> CompletionResult:
147
+ """Append the completion line to the shell profile."""
148
+ try:
149
+ profile_path.parent.mkdir(parents=True, exist_ok=True)
150
+
151
+ # Idempotent: skip if already present
152
+ if profile_path.exists():
153
+ existing = profile_path.read_text()
154
+ if check_marker in existing:
155
+ console.print(
156
+ f"[yellow]Already installed[/yellow] in {profile_path}"
157
+ )
158
+ return CompletionResult(
159
+ status="info",
160
+ message="Already installed",
161
+ shell=shell,
162
+ eval_line=eval_line,
163
+ installed=False,
164
+ install_path=str(profile_path),
165
+ )
166
+
167
+ with profile_path.open("a") as f:
168
+ f.write(f"\n# deepctl (dg) shell completion\n{eval_line}\n")
169
+
170
+ console.print(f"[green]✓[/green] Completion installed to {profile_path}")
171
+ console.print(
172
+ f"[dim]Restart your shell or run:[/dim] source {profile_path}"
173
+ )
174
+
175
+ return CompletionResult(
176
+ status="success",
177
+ message=f"Installed to {profile_path}",
178
+ shell=shell,
179
+ eval_line=eval_line,
180
+ installed=True,
181
+ install_path=str(profile_path),
182
+ )
183
+
184
+ except OSError as e:
185
+ console.print(f"[red]Failed to write to {profile_path}:[/red] {e}")
186
+ return CompletionResult(
187
+ status="error",
188
+ message=str(e),
189
+ shell=shell,
190
+ eval_line=eval_line,
191
+ )
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: deepctl-cmd-completion
3
+ Version: 0.0.2
4
+ Summary: Shell completion command for deepctl
5
+ Author-email: Deepgram <devrel@deepgram.com>
6
+ Maintainer-email: Deepgram <devrel@deepgram.com>
7
+ License-Expression: MIT
8
+ Keywords: deepgram,cli,completion,shell
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: deepctl-core>=0.1.10
18
+ Requires-Dist: click>=8.0.0
19
+ Requires-Dist: rich>=13.0.0
20
+ Requires-Dist: pydantic>=2.0.0
21
+
22
+ # deepctl-cmd-completion
23
+
24
+ > Part of [deepctl](https://github.com/deepgram/cli) — Official Deepgram CLI
25
+
26
+ Shell completion command for deepctl
27
+
28
+ ## Installation
29
+
30
+ This package is included with deepctl and does not need to be installed separately.
31
+
32
+ ### Install deepctl
33
+
34
+ ```bash
35
+ # Install with pip
36
+ pip install deepctl
37
+
38
+ # Or install with uv
39
+ uv tool install deepctl
40
+
41
+ # Or install with pipx
42
+ pipx install deepctl
43
+
44
+ # Or run without installing
45
+ uvx deepctl --help
46
+ pipx run deepctl --help
47
+ ```
48
+
49
+ ## Commands
50
+
51
+ | Command | Entry Point |
52
+ |---------|-------------|
53
+ | `deepctl completion` | `deepctl_cmd_completion.command:CompletionCommand` |
54
+
55
+ ## Dependencies
56
+
57
+ - `click>=8.0.0`
58
+ - `rich>=13.0.0`
59
+ - `pydantic>=2.0.0`
60
+
61
+ ## License
62
+
63
+ MIT — see [LICENSE](../../LICENSE)
@@ -0,0 +1,7 @@
1
+ deepctl_cmd_completion/__init__.py,sha256=35Z7fNH5Co2IxlNhmgKY1nBFLO5U_WUfGSqazP7dNiQ,44
2
+ deepctl_cmd_completion/command.py,sha256=c-Kk2TmkzTGt5QxRH15b5EYZzAXpDhtgvWZQzwIMS3c,6048
3
+ deepctl_cmd_completion-0.0.2.dist-info/METADATA,sha256=T6dpZYi5BbVEN49MDRlRRfgSqJsDMf4rHm3OfIBwRqA,1494
4
+ deepctl_cmd_completion-0.0.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ deepctl_cmd_completion-0.0.2.dist-info/entry_points.txt,sha256=oJLkLkH_Bv0VFo6vBYeO44YzlJ8VV3FzPuwjN_JqOEg,81
6
+ deepctl_cmd_completion-0.0.2.dist-info/top_level.txt,sha256=23ntLi94J3u_wNZx-mewImqoiMmwUhjYnhTjUy8F4jo,23
7
+ deepctl_cmd_completion-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [deepctl.commands]
2
+ completion = deepctl_cmd_completion.command:CompletionCommand
@@ -0,0 +1 @@
1
+ deepctl_cmd_completion