cli/internal/cmd/unifi/cmd_sites.go
Claude 23b82482f2 refactor: rename module from github.com/host-uk/core to forge.lthn.ai/core/cli
Move module identity to our own Forgejo instance. All import paths
updated across 434 Go files, sub-module go.mod files, and go.work.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 05:53:52 +00:00

53 lines
1.1 KiB
Go

package unifi
import (
"forge.lthn.ai/core/cli/pkg/cli"
"forge.lthn.ai/core/cli/pkg/log"
uf "forge.lthn.ai/core/cli/pkg/unifi"
)
// addSitesCommand adds the 'sites' subcommand for listing UniFi sites.
func addSitesCommand(parent *cli.Command) {
cmd := &cli.Command{
Use: "sites",
Short: "List controller sites",
Long: "List all sites configured on the UniFi controller.",
RunE: func(cmd *cli.Command, args []string) error {
return runSites()
},
}
parent.AddCommand(cmd)
}
func runSites() error {
client, err := uf.NewFromConfig("", "", "", "", nil)
if err != nil {
return log.E("unifi.sites", "failed to initialise client", err)
}
sites, err := client.GetSites()
if err != nil {
return log.E("unifi.sites", "failed to fetch sites", err)
}
if len(sites) == 0 {
cli.Text("No sites found.")
return nil
}
table := cli.NewTable("Name", "Description")
for _, s := range sites {
table.AddRow(
valueStyle.Render(s.Name),
dimStyle.Render(s.Desc),
)
}
cli.Blank()
cli.Print(" %d sites\n\n", len(sites))
table.Render()
return nil
}