cli/cmd/forge/cmd_status.go
Snider 1bf130b25a
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
chore: update module paths and daemon refactor
Sync CLI module imports across all command packages.
Refactor daemon command with expanded functionality.
Update go.mod and go.work dependencies.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-02-17 19:19:40 +00:00

63 lines
1.6 KiB
Go

package forge
import (
"fmt"
"forge.lthn.ai/core/go/pkg/cli"
fg "forge.lthn.ai/core/go-scm/forge"
)
// addStatusCommand adds the 'status' subcommand for instance info.
func addStatusCommand(parent *cli.Command) {
cmd := &cli.Command{
Use: "status",
Short: "Show Forgejo instance status",
Long: "Display Forgejo instance version, authenticated user, and summary counts.",
RunE: func(cmd *cli.Command, args []string) error {
return runStatus()
},
}
parent.AddCommand(cmd)
}
func runStatus() error {
client, err := fg.NewFromConfig("", "")
if err != nil {
return err
}
// Get server version
ver, _, err := client.API().ServerVersion()
if err != nil {
return cli.WrapVerb(err, "get", "server version")
}
// Get authenticated user
user, _, err := client.API().GetMyUserInfo()
if err != nil {
return cli.WrapVerb(err, "get", "user info")
}
// Get org count
orgs, err := client.ListMyOrgs()
if err != nil {
return cli.WrapVerb(err, "list", "organisations")
}
// Get repo count
repos, err := client.ListUserRepos()
if err != nil {
return cli.WrapVerb(err, "list", "repositories")
}
cli.Blank()
cli.Print(" %s %s\n", dimStyle.Render("Instance:"), valueStyle.Render(client.URL()))
cli.Print(" %s %s\n", dimStyle.Render("Version:"), valueStyle.Render(ver))
cli.Print(" %s %s\n", dimStyle.Render("User:"), valueStyle.Render(user.UserName))
cli.Print(" %s %s\n", dimStyle.Render("Orgs:"), numberStyle.Render(fmt.Sprintf("%d", len(orgs))))
cli.Print(" %s %s\n", dimStyle.Render("Repos:"), numberStyle.Render(fmt.Sprintf("%d", len(repos))))
cli.Blank()
return nil
}