|
1 | 1 | """ |
2 | | -Update command implementation for KiCad Library Manager (Typer version). |
3 | | -Updates KiLM itself to the latest version. |
| 2 | +Update command group for KiCad Library Manager. |
| 3 | +Contains subcommands for checking, showing info, and performing updates. |
4 | 4 | """ |
5 | 5 |
|
6 | | -import importlib.metadata |
7 | | -from typing import Annotated |
8 | | - |
9 | 6 | import typer |
10 | | -from rich.console import Console |
11 | | -from rich.panel import Panel |
12 | | - |
13 | | -from ...services.update_service import UpdateManager |
14 | | - |
15 | | -console = Console() |
16 | | - |
17 | | - |
18 | | -def update( |
19 | | - check: Annotated[ |
20 | | - bool, typer.Option(help="Check for updates without installing") |
21 | | - ] = False, |
22 | | - force: Annotated[ |
23 | | - bool, typer.Option(help="Force update even if already up to date") |
24 | | - ] = False, |
25 | | -) -> None: |
26 | | - """Update KiLM to the latest version. |
27 | | -
|
28 | | - This command updates KiLM itself by downloading and installing the latest |
29 | | - version from PyPI. The update method depends on how KiLM was installed |
30 | | - (pip, pipx, conda, etc.). |
31 | | -
|
32 | | - ⚠️ DEPRECATION NOTICE: |
33 | | - In KiLM 0.4.0, the 'update' command now updates KiLM itself. |
34 | | - To update library content, use 'kilm sync' instead. |
35 | | - This banner will be removed in a future version. |
36 | | -
|
37 | | - Use --check to see if updates are available without installing. |
38 | | - """ |
39 | | - |
40 | | - deprecation_notice = ( |
41 | | - "[bold yellow]⚠️ BREAKING CHANGE NOTICE (KiLM 0.4.0)[/bold yellow]\n\n" |
42 | | - "The [bold]kilm update[/bold] command now updates KiLM itself.\n" |
43 | | - "To update library content, use [bold cyan]kilm sync[/bold cyan] instead.\n" |
44 | | - "This notice will be removed in a future version." |
45 | | - ) |
46 | | - console.print(Panel(deprecation_notice, expand=False, border_style="yellow")) |
47 | | - |
48 | | - version = importlib.metadata.version("kilm") |
49 | | - |
50 | | - update_manager = UpdateManager(version) |
51 | | - |
52 | | - console.print( |
53 | | - f"[blue]Current KiLM version:[/blue] [bold cyan]v{version}[/bold cyan]" |
54 | | - ) |
55 | | - console.print( |
56 | | - f"[blue]Installation method:[/blue] {update_manager.installation_method}" |
57 | | - ) |
58 | | - console.print("\n[bold cyan]Checking for updates...[/bold cyan]") |
59 | | - |
60 | | - latest_version = update_manager.check_latest_version() |
61 | | - |
62 | | - if latest_version is None: |
63 | | - console.print("[red]Could not check for updates. Please try again later.[/red]") |
64 | | - return |
65 | | - |
66 | | - if not update_manager.is_newer_version_available(latest_version): |
67 | | - if not force: |
68 | | - console.print( |
69 | | - f"[green]KiLM is up to date[/green] [bold green]v{version}[/bold green]" |
70 | | - ) |
71 | | - return |
72 | | - else: |
73 | | - console.print( |
74 | | - f"[yellow]Forcing update to v{latest_version}[/yellow] (current: v{version})" |
75 | | - ) |
76 | | - else: |
77 | | - console.print( |
78 | | - f"[green]New version available:[/green] [bold green]v{latest_version}[/bold green]" |
79 | | - ) |
80 | 7 |
|
81 | | - if check: |
82 | | - if update_manager.is_newer_version_available(latest_version): |
83 | | - console.print( |
84 | | - f"\n[green]Update available:[/green] [bold green]v{latest_version}[/bold green]" |
85 | | - ) |
86 | | - console.print( |
87 | | - f"[blue]To update, run:[/blue] [cyan]{update_manager.get_update_instruction()}[/cyan]" |
88 | | - ) |
89 | | - else: |
90 | | - console.print("[green]No updates available[/green]") |
91 | | - return |
| 8 | +from .check import check_update_command |
| 9 | +from .info import info_command |
| 10 | +from .perform import perform_update_command |
92 | 11 |
|
93 | | - # Perform the update |
94 | | - if update_manager.can_auto_update(): |
95 | | - console.print( |
96 | | - f"\n[bold cyan]Updating KiLM to version {latest_version}...[/bold cyan]" |
97 | | - ) |
98 | | - success, message = update_manager.perform_update() |
| 12 | +# Create the update command group |
| 13 | +update_app = typer.Typer( |
| 14 | + name="update", help="Update KiLM CLI to the latest version", no_args_is_help=True |
| 15 | +) |
99 | 16 |
|
100 | | - if success: |
101 | | - console.print(f"[bold green]✅ {message}[/bold green]") |
102 | | - console.print( |
103 | | - f"[green]KiLM has been updated to version {latest_version}[/green]" |
104 | | - ) |
105 | | - else: |
106 | | - console.print(f"[bold red]❌ {message}[/bold red]") |
107 | | - else: |
108 | | - instruction = update_manager.get_update_instruction() |
109 | | - console.print( |
110 | | - f"\n[yellow]Manual update required for {update_manager.installation_method} installation.[/yellow]" |
111 | | - ) |
112 | | - console.print(f"[blue]Please run:[/blue] [cyan]{instruction}[/cyan]") |
| 17 | +# Register subcommands |
| 18 | +update_app.command("check")(check_update_command) |
| 19 | +update_app.command("info")(info_command) |
| 20 | +update_app.command("perform")(perform_update_command) |
0 commit comments