Replace leaanthony/clir with spf13/cobra across all command packages. This provides better subcommand handling, built-in shell completion, and a more widely-used CLI framework. Changes: - Update cmd/core.go with cobra root command and completion support - Convert all subcommand packages to use *cobra.Command - Use init() functions for flag registration instead of inline setup - Maintain all existing functionality and flag behaviors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
// Package doctor provides environment check commands.
|
|
package doctor
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/host-uk/core/cmd/shared"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Style aliases from shared
|
|
var (
|
|
successStyle = shared.SuccessStyle
|
|
errorStyle = shared.ErrorStyle
|
|
dimStyle = shared.DimStyle
|
|
)
|
|
|
|
// Flag variable for doctor command
|
|
var doctorVerbose bool
|
|
|
|
var doctorCmd = &cobra.Command{
|
|
Use: "doctor",
|
|
Short: "Check development environment",
|
|
Long: `Checks that all required tools are installed and configured.
|
|
Run this before 'core setup' to ensure your environment is ready.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runDoctor(doctorVerbose)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
doctorCmd.Flags().BoolVar(&doctorVerbose, "verbose", false, "Show detailed version information")
|
|
}
|
|
|
|
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
|
|
}
|