bd-bok: Add --yes/-y flag to bd doctor --fix for non-interactive mode

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-28 21:56:33 -08:00
parent 284d61420e
commit 9d896c3b28

View File

@@ -48,6 +48,7 @@ type doctorResult struct {
var ( var (
doctorFix bool doctorFix bool
doctorYes bool
perfMode bool perfMode bool
checkHealthMode bool checkHealthMode bool
) )
@@ -87,7 +88,8 @@ Examples:
bd doctor # Check current directory bd doctor # Check current directory
bd doctor /path/to/repo # Check specific repository bd doctor /path/to/repo # Check specific repository
bd doctor --json # Machine-readable output bd doctor --json # Machine-readable output
bd doctor --fix # Automatically fix issues bd doctor --fix # Automatically fix issues (with confirmation)
bd doctor --fix --yes # Automatically fix issues (no confirmation)
bd doctor --perf # Performance diagnostics`, bd doctor --perf # Performance diagnostics`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// Use global jsonOutput set by PersistentPreRun // Use global jsonOutput set by PersistentPreRun
@@ -143,6 +145,7 @@ Examples:
func init() { func init() {
doctorCmd.Flags().BoolVar(&doctorFix, "fix", false, "Automatically fix issues where possible") doctorCmd.Flags().BoolVar(&doctorFix, "fix", false, "Automatically fix issues where possible")
doctorCmd.Flags().BoolVarP(&doctorYes, "yes", "y", false, "Skip confirmation prompt (for non-interactive use)")
} }
func applyFixes(result doctorResult) { func applyFixes(result doctorResult) {
@@ -165,19 +168,21 @@ func applyFixes(result doctorResult) {
fmt.Printf(" %d. %s: %s\n", i+1, issue.Name, issue.Message) fmt.Printf(" %d. %s: %s\n", i+1, issue.Name, issue.Message)
} }
// Ask for confirmation // Ask for confirmation (skip if --yes flag is set)
fmt.Printf("\nThis will attempt to fix %d issue(s). Continue? (Y/n): ", len(fixableIssues)) if !doctorYes {
reader := bufio.NewReader(os.Stdin) fmt.Printf("\nThis will attempt to fix %d issue(s). Continue? (Y/n): ", len(fixableIssues))
response, err := reader.ReadString('\n') reader := bufio.NewReader(os.Stdin)
if err != nil { response, err := reader.ReadString('\n')
fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err) if err != nil {
return fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
} return
}
response = strings.TrimSpace(strings.ToLower(response)) response = strings.TrimSpace(strings.ToLower(response))
if response != "" && response != "y" && response != "yes" { if response != "" && response != "y" && response != "yes" {
fmt.Println("Fix canceled.") fmt.Println("Fix canceled.")
return return
}
} }
// Apply fixes // Apply fixes