cli/cmd/module/cmd_update.go
Claude 41f786a222
Some checks are pending
Security Scan / Go Vulnerability Check (push) Waiting to run
Security Scan / Secret Detection (push) Waiting to run
Security Scan / Dependency & Config Scan (push) Waiting to run
feat(module): add CLI commands for marketplace module management
Wire `core module install/remove/list/update` commands to the
marketplace.Installer from pkg/marketplace. Follows the exact
pattern established by cmd/plugin/.

- install: clone from Git repo with optional ed25519 verification
- list: table output of installed modules
- update: pull latest + re-verify manifest (supports --all)
- remove: confirmation prompt then cleanup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 10:37:52 +00:00

84 lines
1.7 KiB
Go

package module
import (
"context"
"fmt"
"forge.lthn.ai/core/go/pkg/cli"
"forge.lthn.ai/core/go/pkg/i18n"
)
var updateAll bool
func addUpdateCommand(parent *cli.Command) {
updateCmd := cli.NewCommand(
"update [code]",
i18n.T("Update a module or all modules"),
i18n.T("Update a specific module to the latest version, or use --all to update all installed modules."),
func(cmd *cli.Command, args []string) error {
if updateAll {
return runUpdateAll()
}
if len(args) == 0 {
return fmt.Errorf("module code required (or use --all)")
}
return runUpdate(args[0])
},
)
cli.BoolFlag(updateCmd, &updateAll, "all", "a", false, i18n.T("Update all installed modules"))
parent.AddCommand(updateCmd)
}
func runUpdate(code string) error {
_, st, inst, err := moduleSetup()
if err != nil {
return err
}
defer st.Close()
cli.Dim("Updating " + code + "...")
if err := inst.Update(context.Background(), code); err != nil {
return err
}
cli.Success("Module " + code + " updated successfully")
return nil
}
func runUpdateAll() error {
_, st, inst, err := moduleSetup()
if err != nil {
return err
}
defer st.Close()
installed, err := inst.Installed()
if err != nil {
return err
}
if len(installed) == 0 {
cli.Dim("No modules installed")
return nil
}
ctx := context.Background()
var updated, failed int
for _, m := range installed {
cli.Dim("Updating " + m.Code + "...")
if err := inst.Update(ctx, m.Code); err != nil {
cli.Errorf("Failed to update %s: %v", m.Code, err)
failed++
continue
}
cli.Success(m.Code + " updated")
updated++
}
fmt.Println()
cli.Dim(fmt.Sprintf("%d updated, %d failed", updated, failed))
return nil
}