Repository navigation
Expand file tree
/
Copy pathcommand_list.py
More file actions
75 lines (63 loc) · 2.89 KB
/
Copy pathcommand_list.py
File metadata and controls
75 lines (63 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Implementation of ``specify extension list``.
Registered by ``_commands.register()``; shared command infrastructure lives in
``_commands.py``.
"""
from __future__ import annotations
import typer
from rich.markup import escape as _escape_markup
from .._console import console
from .._installed_list_json import (
InstalledListJSONCommand,
emit_json,
emit_json_error,
installed_list_item,
)
from .._project import resolve_specify_project_root
from . import _commands
@_commands.extension_app.command("list", cls=InstalledListJSONCommand)
def extension_list(
available: bool = typer.Option(False, "--available", help="Show available extensions from catalog"),
all_extensions: bool = typer.Option(False, "--all", help="Show both installed and available"),
json_output: bool = typer.Option(False, "--json", help="Output installed extensions as JSON"),
):
"""List installed extensions."""
from . import ExtensionManager, normalize_priority
if json_output:
try:
project_root = resolve_specify_project_root()
manager = ExtensionManager(project_root)
installed = manager.list_installed()
installed = sorted(
installed,
key=lambda extension: (
normalize_priority(extension.get("priority")),
str(extension.get("id", "")),
),
)
emit_json(
[installed_list_item(ext, include_hooks=True) for ext in installed]
)
return
except Exception as error:
emit_json_error(error)
project_root = _commands._require_specify_project()
manager = ExtensionManager(project_root)
installed = manager.list_installed()
if not installed and not (available or all_extensions):
console.print("[yellow]No extensions installed.[/yellow]")
console.print("\nInstall an extension with:")
console.print(" specify extension add <extension-name>")
return
if installed:
console.print("\n[bold cyan]Installed Extensions:[/bold cyan]\n")
for ext in installed:
status_icon = "✓" if ext["enabled"] else "✗"
status_color = "green" if ext["enabled"] else "red"
console.print(f" [{status_color}]{status_icon}[/{status_color}] [bold]{_escape_markup(ext['name'])}[/bold] (v{_escape_markup(str(ext['version']))})")
console.print(f" [dim]{_escape_markup(ext['id'])}[/dim]")
console.print(f" {_escape_markup(ext['description'])}")
console.print(f" Commands: {ext['command_count']} | Hooks: {ext['hook_count']} | Priority: {ext['priority']} | Status: {'Enabled' if ext['enabled'] else 'Disabled'}")
console.print()
if available or all_extensions:
console.print("\nInstall an extension:")
console.print(" [cyan]specify extension add <name>[/cyan]")