refactor(cli): restructure cmd packages into subdirectories
- Move CLI commands into subdirectories matching command hierarchy:
dev/, go/, php/, build/, ci/, sdk/, pkg/, vm/, docs/, setup/, doctor/, test/, ai/
- Create shared/ package for common styles and utilities
- Add new `core ai` root command with claude subcommand
- Update package declarations and imports across all files
- Create commands.go entry points for each package
- Remove GUI-related files (moved to core-gui repo)
This makes the filesystem structure match the CLI command structure,
improving context capture and code organization.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:02:43 +00:00
|
|
|
package dev
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"sort"
|
|
|
|
|
|
2026-01-28 15:29:42 +00:00
|
|
|
"github.com/host-uk/core/pkg/git"
|
|
|
|
|
"github.com/host-uk/core/pkg/repos"
|
2026-01-27 21:08:51 +00:00
|
|
|
"github.com/leaanthony/clir"
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-30 00:22:47 +00:00
|
|
|
// addHealthCommand adds the 'health' command to the given parent command.
|
|
|
|
|
func addHealthCommand(parent *clir.Command) {
|
2026-01-27 21:08:51 +00:00
|
|
|
var registryPath string
|
|
|
|
|
var verbose bool
|
|
|
|
|
|
|
|
|
|
healthCmd := parent.NewSubCommand("health", "Quick health check across all repos")
|
|
|
|
|
healthCmd.LongDescription("Shows a summary of repository health:\n" +
|
|
|
|
|
"total repos, dirty repos, unpushed commits, etc.")
|
|
|
|
|
|
|
|
|
|
healthCmd.StringFlag("registry", "Path to repos.yaml (auto-detected if not specified)", ®istryPath)
|
|
|
|
|
healthCmd.BoolFlag("verbose", "Show detailed breakdown", &verbose)
|
|
|
|
|
|
|
|
|
|
healthCmd.Action(func() error {
|
|
|
|
|
return runHealth(registryPath, verbose)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runHealth(registryPath string, verbose bool) error {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
// Find or use provided registry, fall back to directory scan
|
|
|
|
|
var reg *repos.Registry
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
if registryPath != "" {
|
|
|
|
|
reg, err = repos.LoadRegistry(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to load registry: %w", err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
registryPath, err = repos.FindRegistry()
|
|
|
|
|
if err == nil {
|
|
|
|
|
reg, err = repos.LoadRegistry(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to load registry: %w", err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback: scan current directory
|
|
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
|
reg, err = repos.ScanDirectory(cwd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to scan directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build paths and names for git operations
|
|
|
|
|
var paths []string
|
|
|
|
|
names := make(map[string]string)
|
|
|
|
|
|
|
|
|
|
for _, repo := range reg.List() {
|
|
|
|
|
if repo.IsGitRepo() {
|
|
|
|
|
paths = append(paths, repo.Path)
|
|
|
|
|
names[repo.Path] = repo.Name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(paths) == 0 {
|
|
|
|
|
fmt.Println("No git repositories found.")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get status for all repos
|
|
|
|
|
statuses := git.Status(ctx, git.StatusOptions{
|
|
|
|
|
Paths: paths,
|
|
|
|
|
Names: names,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Sort for consistent verbose output
|
|
|
|
|
sort.Slice(statuses, func(i, j int) bool {
|
|
|
|
|
return statuses[i].Name < statuses[j].Name
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Aggregate stats
|
|
|
|
|
var (
|
2026-01-30 00:22:47 +00:00
|
|
|
totalRepos = len(statuses)
|
|
|
|
|
dirtyRepos []string
|
|
|
|
|
aheadRepos []string
|
|
|
|
|
behindRepos []string
|
|
|
|
|
errorRepos []string
|
2026-01-27 21:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for _, s := range statuses {
|
|
|
|
|
if s.Error != nil {
|
|
|
|
|
errorRepos = append(errorRepos, s.Name)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if s.IsDirty() {
|
|
|
|
|
dirtyRepos = append(dirtyRepos, s.Name)
|
|
|
|
|
}
|
|
|
|
|
if s.HasUnpushed() {
|
|
|
|
|
aheadRepos = append(aheadRepos, s.Name)
|
|
|
|
|
}
|
|
|
|
|
if s.HasUnpulled() {
|
|
|
|
|
behindRepos = append(behindRepos, s.Name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print summary line
|
|
|
|
|
fmt.Println()
|
|
|
|
|
printHealthSummary(totalRepos, dirtyRepos, aheadRepos, behindRepos, errorRepos)
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
|
|
// Verbose output
|
|
|
|
|
if verbose {
|
|
|
|
|
if len(dirtyRepos) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Printf("%s %s\n", warningStyle.Render("Dirty:"), formatRepoList(dirtyRepos))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if len(aheadRepos) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Printf("%s %s\n", successStyle.Render("Ahead:"), formatRepoList(aheadRepos))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if len(behindRepos) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Printf("%s %s\n", warningStyle.Render("Behind:"), formatRepoList(behindRepos))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if len(errorRepos) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Printf("%s %s\n", errorStyle.Render("Errors:"), formatRepoList(errorRepos))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printHealthSummary(total int, dirty, ahead, behind, errors []string) {
|
|
|
|
|
// Total repos
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(valueStyle.Render(fmt.Sprintf("%d", total)))
|
|
|
|
|
fmt.Print(dimStyle.Render(" repos"))
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
// Separator
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(dimStyle.Render(" | "))
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
// Dirty
|
|
|
|
|
if len(dirty) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(warningStyle.Render(fmt.Sprintf("%d", len(dirty))))
|
|
|
|
|
fmt.Print(dimStyle.Render(" dirty"))
|
2026-01-27 21:08:51 +00:00
|
|
|
} else {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(successStyle.Render("clean"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Separator
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(dimStyle.Render(" | "))
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
// Ahead
|
|
|
|
|
if len(ahead) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(valueStyle.Render(fmt.Sprintf("%d", len(ahead))))
|
|
|
|
|
fmt.Print(dimStyle.Render(" to push"))
|
2026-01-27 21:08:51 +00:00
|
|
|
} else {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(successStyle.Render("synced"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Separator
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(dimStyle.Render(" | "))
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
// Behind
|
|
|
|
|
if len(behind) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(warningStyle.Render(fmt.Sprintf("%d", len(behind))))
|
|
|
|
|
fmt.Print(dimStyle.Render(" to pull"))
|
2026-01-27 21:08:51 +00:00
|
|
|
} else {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(successStyle.Render("up to date"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Errors (only if any)
|
|
|
|
|
if len(errors) > 0 {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Print(dimStyle.Render(" | "))
|
|
|
|
|
fmt.Print(errorStyle.Render(fmt.Sprintf("%d", len(errors))))
|
|
|
|
|
fmt.Print(dimStyle.Render(" errors"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:22:47 +00:00
|
|
|
func formatRepoList(reposList []string) string {
|
|
|
|
|
if len(reposList) <= 5 {
|
|
|
|
|
return joinRepos(reposList)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
2026-01-30 00:22:47 +00:00
|
|
|
return joinRepos(reposList[:5]) + fmt.Sprintf(" +%d more", len(reposList)-5)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:22:47 +00:00
|
|
|
func joinRepos(reposList []string) string {
|
2026-01-27 21:08:51 +00:00
|
|
|
result := ""
|
2026-01-30 00:22:47 +00:00
|
|
|
for i, r := range reposList {
|
2026-01-27 21:08:51 +00:00
|
|
|
if i > 0 {
|
|
|
|
|
result += ", "
|
|
|
|
|
}
|
|
|
|
|
result += r
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|