Skip to content

Commit a5e5242

Browse files
kivo360claude
andcommitted
feat(cli): omoios completion show / install — zsh / bash / fish
Phase 3 of the four-piece roadmap. Wraps cyclopts' built-in completion generator (`app.generate_completion`, `app.install_completion`) with two user-facing modes per the design call: - `omoios completion show [zsh|bash|fish]` Prints the script to stdout (raw, no Rich formatting) so it can be eval'd from a dotfile: eval "$(omoios completion show zsh)" Auto-detects $SHELL when the argument is omitted. - `omoios completion install [zsh|bash|fish] [--output PATH] [--no-startup]` Writes to the shell's standard completion location and (by default) appends a `source` line to the matching RC file. `--no-startup` skips the RC write for users who manage their fpath manually. Both rely on cyclopts ≥4.4 — earlier versions don't expose these methods. Lazy-imports the root `app` from `omoios.cli.main` to dodge the circular import. Generated zsh script discovered via `omoios completion show zsh`: #compdef omoios _omoios() { ... 'workspaces:…' 'environments:…' 'providers:…' 'sessions:…' 'webhooks:…' 'artifacts:…' 'connections:…' 'usage:…' ... } Bash variant covers options-with-values + per-subcommand argument lists. Fish supported the same way. Tests: 14/14 still green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cf9cdd4 commit a5e5242

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""`omoios completion` — shell completion management.
2+
3+
Two modes (per the design call): eval-friendly + file-install. Cyclopts
4+
ships the actual completion-script generation; this module is just the
5+
user-facing CLI wrapper that exposes both shapes.
6+
7+
- `omoios completion show [SHELL]` — print the script to stdout
8+
(for `eval "$(omoios completion show zsh)"` in dotfiles).
9+
- `omoios completion install [SHELL]` — write the completion script
10+
to the shell's standard location and append a source line to the
11+
matching RC file. Uses cyclopts' built-in `install_completion`.
12+
13+
Both auto-detect `$SHELL` when the argument is omitted.
14+
"""
15+
16+
from __future__ import annotations
17+
18+
from typing import Annotated, Literal, Optional
19+
20+
from cyclopts import App, Parameter
21+
22+
from omoios.cli._ui import CliError, console, ok
23+
24+
25+
completion_app = App(
26+
name="completion",
27+
help="Generate or install shell completion (zsh / bash / fish).",
28+
)
29+
30+
31+
@completion_app.command(name="show")
32+
def show_cmd(
33+
shell: Annotated[
34+
Optional[Literal["zsh", "bash", "fish"]],
35+
Parameter(help="Target shell. Auto-detected from $SHELL if omitted."),
36+
] = None,
37+
) -> None:
38+
"""Print the completion script to stdout (eval-friendly)."""
39+
# Lazy import to avoid circulating with `omoios.cli.main`.
40+
from omoios.cli.main import app
41+
42+
try:
43+
script = app.generate_completion(shell=shell, prog_name="omoios")
44+
except Exception as exc: # noqa: BLE001 — translate cyclopts' own errors
45+
raise CliError(f"could not generate completion: {exc}") from exc
46+
47+
# `console.print` would Rich-format; we want raw shell so it's eval-able.
48+
print(script)
49+
50+
51+
@completion_app.command(name="install")
52+
def install_cmd(
53+
shell: Annotated[
54+
Optional[Literal["zsh", "bash", "fish"]],
55+
Parameter(help="Target shell. Auto-detected from $SHELL if omitted."),
56+
] = None,
57+
output: Annotated[
58+
Optional[str],
59+
Parameter(
60+
name=["--output", "-o"],
61+
help=(
62+
"Override the install location. Defaults to the shell's "
63+
"standard completion path."
64+
),
65+
),
66+
] = None,
67+
no_startup: Annotated[
68+
bool,
69+
Parameter(
70+
name="--no-startup",
71+
help="Skip appending a source line to the shell RC file.",
72+
),
73+
] = False,
74+
) -> None:
75+
"""Install the completion script to the shell's standard location."""
76+
from pathlib import Path
77+
78+
from omoios.cli.main import app
79+
80+
try:
81+
path = app.install_completion(
82+
shell=shell,
83+
output=Path(output) if output else None,
84+
add_to_startup=not no_startup,
85+
)
86+
except Exception as exc: # noqa: BLE001
87+
raise CliError(f"could not install completion: {exc}") from exc
88+
89+
ok(f"installed completion → [dim]{path}[/dim]")
90+
if not no_startup:
91+
console.print(
92+
" [dim]source line appended to your shell rc; restart the "
93+
"shell or `source` it to activate.[/dim]"
94+
)

‎sdk/python/omoios/cli/main.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from omoios.cli._ui import CliError, die, err_console
2929
from omoios.cli.artifacts import artifacts_app
3030
from omoios.cli.auth import auth_app
31+
from omoios.cli.completion import completion_app
3132
from omoios.cli.config import config_app
3233
from omoios.cli.connections import connections_app
3334
from omoios.cli.environments import environments_app
@@ -60,6 +61,7 @@
6061
app.command(usage_app)
6162
app.command(auth_app)
6263
app.command(config_app)
64+
app.command(completion_app)
6365
app.command(signup)
6466
app.command(whoami)
6567

0 commit comments

Comments
 (0)