Add doctor package with: - Check interface for implementing health checks - CheckContext for passing context to checks - CheckResult and CheckStatus types - Report with summary and pretty printing - Doctor runner with Run() and Fix() methods - BaseCheck and FixableCheck for easy check implementation - CLI command: gt doctor [--fix] [--verbose] [--rig <name>] Built-in checks will be added in: - gt-f9x.5: Town-level checks (config, state, mail, rigs) - gt-f9x.6: Rig-level checks (refinery, clones, gitignore) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/gastown/internal/doctor"
|
|
"github.com/steveyegge/gastown/internal/workspace"
|
|
)
|
|
|
|
var (
|
|
doctorFix bool
|
|
doctorVerbose bool
|
|
doctorRig string
|
|
)
|
|
|
|
var doctorCmd = &cobra.Command{
|
|
Use: "doctor",
|
|
Short: "Run health checks on the workspace",
|
|
Long: `Run diagnostic checks on the Gas Town workspace.
|
|
|
|
Doctor checks for common configuration issues, missing files,
|
|
and other problems that could affect workspace operation.
|
|
|
|
Use --fix to attempt automatic fixes for issues that support it.
|
|
Use --rig to check a specific rig instead of the entire workspace.`,
|
|
RunE: runDoctor,
|
|
}
|
|
|
|
func init() {
|
|
doctorCmd.Flags().BoolVar(&doctorFix, "fix", false, "Attempt to automatically fix issues")
|
|
doctorCmd.Flags().BoolVarP(&doctorVerbose, "verbose", "v", false, "Show detailed output")
|
|
doctorCmd.Flags().StringVar(&doctorRig, "rig", "", "Check specific rig only")
|
|
rootCmd.AddCommand(doctorCmd)
|
|
}
|
|
|
|
func runDoctor(cmd *cobra.Command, args []string) error {
|
|
// Find town root
|
|
townRoot, err := workspace.FindFromCwdOrError()
|
|
if err != nil {
|
|
return fmt.Errorf("not in a Gas Town workspace: %w", err)
|
|
}
|
|
|
|
// Create check context
|
|
ctx := &doctor.CheckContext{
|
|
TownRoot: townRoot,
|
|
RigName: doctorRig,
|
|
Verbose: doctorVerbose,
|
|
}
|
|
|
|
// Create doctor and register checks
|
|
d := doctor.NewDoctor()
|
|
|
|
// Register built-in checks
|
|
// Note: Town-level checks are registered in gt-f9x.5
|
|
// Rig-level checks are registered in gt-f9x.6
|
|
// For now, we just have the framework ready
|
|
|
|
// If no checks registered, inform user
|
|
if len(d.Checks()) == 0 {
|
|
fmt.Println("No health checks registered yet.")
|
|
fmt.Println("Town-level and rig-level checks will be added in future updates.")
|
|
return nil
|
|
}
|
|
|
|
// Run checks
|
|
var report *doctor.Report
|
|
if doctorFix {
|
|
report = d.Fix(ctx)
|
|
} else {
|
|
report = d.Run(ctx)
|
|
}
|
|
|
|
// Print report
|
|
report.Print(os.Stdout, doctorVerbose)
|
|
|
|
// Exit with error code if there are errors
|
|
if report.HasErrors() {
|
|
return fmt.Errorf("doctor found %d error(s)", report.Summary.Errors)
|
|
}
|
|
|
|
return nil
|
|
}
|