cli/internal/cmd/plugin/cmd_update.go
Snider abe74a1a3d refactor: split CLI from monorepo, import core/go as library (#1)
- Change module from forge.lthn.ai/core/go to forge.lthn.ai/core/cli
- Remove pkg/ directory (now served from core/go)
- Add require + replace for forge.lthn.ai/core/go => ../go
- Update go.work to include ../go workspace module
- Fix all internal/cmd/* imports: pkg/ refs → forge.lthn.ai/core/go/pkg/
- Rename internal/cmd/sdk package to sdkcmd (avoids conflict with pkg/sdk)
- Remove SDK library files from internal/cmd/sdk/ (now in core/go/pkg/sdk/)
- Remove duplicate RAG helper functions from internal/cmd/rag/
- Remove stale cmd/core-ide/ (now in core/ide repo)
- Update IDE variant to remove core-ide import
- Fix test assertion for new module name
- Run go mod tidy to sync dependencies

core/cli is now a pure CLI application importing core/go for packages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Co-authored-by: Claude <developers@lethean.io>
Reviewed-on: #1
2026-02-16 14:24:37 +00:00

94 lines
2 KiB
Go

package plugin
import (
"context"
"fmt"
"forge.lthn.ai/core/go/pkg/cli"
"forge.lthn.ai/core/go/pkg/i18n"
"forge.lthn.ai/core/go/pkg/io"
"forge.lthn.ai/core/go/pkg/plugin"
)
var updateAll bool
func addUpdateCommand(parent *cli.Command) {
updateCmd := cli.NewCommand(
"update [name]",
i18n.T("Update a plugin or all plugins"),
i18n.T("Update a specific plugin to the latest version, or use --all to update all installed plugins."),
func(cmd *cli.Command, args []string) error {
if updateAll {
return runUpdateAll()
}
if len(args) == 0 {
return fmt.Errorf("plugin name required (or use --all)")
}
return runUpdate(args[0])
},
)
cli.BoolFlag(updateCmd, &updateAll, "all", "a", false, i18n.T("Update all installed plugins"))
parent.AddCommand(updateCmd)
}
func runUpdate(name string) error {
basePath, err := pluginBasePath()
if err != nil {
return err
}
registry := plugin.NewRegistry(io.Local, basePath)
if err := registry.Load(); err != nil {
return err
}
installer := plugin.NewInstaller(io.Local, registry)
cli.Dim("Updating " + name + "...")
if err := installer.Update(context.Background(), name); err != nil {
return err
}
cli.Success("Plugin " + name + " updated successfully")
return nil
}
func runUpdateAll() error {
basePath, err := pluginBasePath()
if err != nil {
return err
}
registry := plugin.NewRegistry(io.Local, basePath)
if err := registry.Load(); err != nil {
return err
}
plugins := registry.List()
if len(plugins) == 0 {
cli.Dim("No plugins installed")
return nil
}
installer := plugin.NewInstaller(io.Local, registry)
ctx := context.Background()
var updated, failed int
for _, p := range plugins {
cli.Dim("Updating " + p.Name + "...")
if err := installer.Update(ctx, p.Name); err != nil {
cli.Errorf("Failed to update %s: %v", p.Name, err)
failed++
continue
}
cli.Success(p.Name + " updated")
updated++
}
fmt.Println()
cli.Dim(fmt.Sprintf("%d updated, %d failed", updated, failed))
return nil
}