go-scm/cmd/forge/cmd_status.go
Claude d67ac486ff
Some checks failed
Security Scan / security (push) Failing after 8s
Test / test (push) Successful in 4m5s
feat: upgrade to core v0.8.0-alpha.1, replace banned stdlib imports
Migrate git/service.go to Action-based API. Replace fmt, strings,
path/filepath with Core primitives across 77 files (~400 call sites).
Keep encoding/json, strings.EqualFold/SplitSeq/Fields, filepath.Abs/Rel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 13:44:13 +00:00

63 lines
1.6 KiB
Go

package forge
import (
core "dappco.re/go/core"
"forge.lthn.ai/core/cli/pkg/cli"
fg "dappco.re/go/core/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(core.Sprintf("%d", len(orgs))))
cli.Print(" %s %s\n", dimStyle.Render("Repos:"), numberStyle.Render(core.Sprintf("%d", len(repos))))
cli.Blank()
return nil
}