Split all cmd/* packages for maintainability, following the pattern established in cmd/php. Each package now has: - Main file with styles (using cmd/shared) and Add*Commands function - Separate files for logical command groupings Packages refactored: - cmd/dev: 13 files (was 2779 lines in one file) - cmd/build: 5 files (was 913 lines) - cmd/setup: 6 files (was 961 lines) - cmd/go: 5 files (was 655 lines) - cmd/pkg: 5 files (was 634 lines) - cmd/vm: 4 files (was 717 lines) - cmd/ai: 5 files (was 800 lines) - cmd/docs: 5 files (was 379 lines) - cmd/doctor: 5 files (was 301 lines) - cmd/test: 3 files (was 429 lines) - cmd/ci: 5 files (was 272 lines) All packages now import shared styles from cmd/shared instead of redefining them locally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
104 lines
2.7 KiB
Go
104 lines
2.7 KiB
Go
// Package doctor provides environment check commands.
|
|
package doctor
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/host-uk/core/cmd/shared"
|
|
"github.com/leaanthony/clir"
|
|
)
|
|
|
|
// Style aliases from shared
|
|
var (
|
|
successStyle = shared.SuccessStyle
|
|
errorStyle = shared.ErrorStyle
|
|
dimStyle = shared.DimStyle
|
|
)
|
|
|
|
// AddDoctorCommand adds the 'doctor' command to the given parent command.
|
|
func AddDoctorCommand(parent *clir.Cli) {
|
|
var verbose bool
|
|
|
|
doctorCmd := parent.NewSubCommand("doctor", "Check development environment")
|
|
doctorCmd.LongDescription("Checks that all required tools are installed and configured.\n" +
|
|
"Run this before `core setup` to ensure your environment is ready.")
|
|
|
|
doctorCmd.BoolFlag("verbose", "Show detailed version information", &verbose)
|
|
|
|
doctorCmd.Action(func() error {
|
|
return runDoctor(verbose)
|
|
})
|
|
}
|
|
|
|
func runDoctor(verbose bool) error {
|
|
fmt.Println("Checking development environment...")
|
|
fmt.Println()
|
|
|
|
var passed, failed, optional int
|
|
|
|
// Check required tools
|
|
fmt.Println("Required:")
|
|
for _, c := range requiredChecks {
|
|
ok, version := runCheck(c)
|
|
if ok {
|
|
if verbose && version != "" {
|
|
fmt.Printf(" %s %s %s\n", successStyle.Render("✓"), c.name, dimStyle.Render(version))
|
|
} else {
|
|
fmt.Printf(" %s %s\n", successStyle.Render("✓"), c.name)
|
|
}
|
|
passed++
|
|
} else {
|
|
fmt.Printf(" %s %s - %s\n", errorStyle.Render("✗"), c.name, c.description)
|
|
failed++
|
|
}
|
|
}
|
|
|
|
// Check optional tools
|
|
fmt.Println("\nOptional:")
|
|
for _, c := range optionalChecks {
|
|
ok, version := runCheck(c)
|
|
if ok {
|
|
if verbose && version != "" {
|
|
fmt.Printf(" %s %s %s\n", successStyle.Render("✓"), c.name, dimStyle.Render(version))
|
|
} else {
|
|
fmt.Printf(" %s %s\n", successStyle.Render("✓"), c.name)
|
|
}
|
|
passed++
|
|
} else {
|
|
fmt.Printf(" %s %s - %s\n", dimStyle.Render("○"), c.name, dimStyle.Render(c.description))
|
|
optional++
|
|
}
|
|
}
|
|
|
|
// Check GitHub access
|
|
fmt.Println("\nGitHub Access:")
|
|
if checkGitHubSSH() {
|
|
fmt.Printf(" %s SSH key found\n", successStyle.Render("✓"))
|
|
} else {
|
|
fmt.Printf(" %s SSH key missing - run: ssh-keygen && gh ssh-key add\n", errorStyle.Render("✗"))
|
|
failed++
|
|
}
|
|
|
|
if checkGitHubCLI() {
|
|
fmt.Printf(" %s CLI authenticated\n", successStyle.Render("✓"))
|
|
} else {
|
|
fmt.Printf(" %s CLI authentication - run: gh auth login\n", errorStyle.Render("✗"))
|
|
failed++
|
|
}
|
|
|
|
// Check workspace
|
|
fmt.Println("\nWorkspace:")
|
|
checkWorkspace()
|
|
|
|
// Summary
|
|
fmt.Println()
|
|
if failed > 0 {
|
|
fmt.Printf("%s %d issues found\n", errorStyle.Render("Doctor:"), failed)
|
|
fmt.Println("\nInstall missing tools:")
|
|
printInstallInstructions()
|
|
return fmt.Errorf("%d required tools missing", failed)
|
|
}
|
|
|
|
fmt.Printf("%s Environment ready\n", successStyle.Render("Doctor:"))
|
|
return nil
|
|
}
|