opencode-provider-switch/internal/cli/doctor.go
apale7 5c4f60f2b7 feat(desktop): finish Windows GUI integration
Bring the Wails desktop shell to feature parity with the CLI for provider and alias management while keeping the browser fallback working. Wire tray, notifications, autostart, and GUI warnings so desktop flows behave predictably.
2026-04-19 01:02:16 +08:00

56 lines
2.1 KiB
Go

package cli
import (
"fmt"
"github.com/spf13/cobra"
)
func newDoctorCmd() *cobra.Command {
return &cobra.Command{
Use: "doctor",
Short: "Validate ocswitch config (static checks, no upstream requests)",
Long: `doctor performs static validation for local ocswitch config and the expected
OpenCode sync result.
It loads local ocswitch config, checks alias/provider consistency, resolves the
default OpenCode sync target, and validates what provider.ocswitch would look like
there. It does not send any real requests to upstream providers and does not
consume model quota.
Run doctor before opencode sync or serve whenever you changed providers,
aliases, or local server settings.`,
Example: ` ocswitch doctor
ocswitch --config /path/to/config.json doctor`,
RunE: func(cmd *cobra.Command, args []string) error {
report, err := appService().RunDoctor(cmd.Context())
if err != nil {
for _, issue := range report.Issues {
fmt.Fprintf(cmd.OutOrStdout(), " - %s\n", issue.Message)
}
fmt.Fprintf(cmd.OutOrStdout(), " providers: %d\n", report.ProviderCount)
fmt.Fprintf(cmd.OutOrStdout(), " aliases: %d\n", report.AliasCount)
marker := "(will be created)"
if report.OpenCodeTargetFound {
marker = "(exists)"
}
fmt.Fprintf(cmd.OutOrStdout(), " opencode config target: %s %s\n", report.OpenCodeTargetPath, marker)
fmt.Fprintf(cmd.OutOrStdout(), " provider.ocswitch preview: valid=%v\n", report.OK)
fmt.Fprintf(cmd.OutOrStdout(), " proxy bind: %s\n", report.ProxyBindAddress)
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "✓ config loaded: %s\n", report.ConfigPath)
fmt.Fprintf(cmd.OutOrStdout(), " providers: %d\n", report.ProviderCount)
fmt.Fprintf(cmd.OutOrStdout(), " aliases: %d\n", report.AliasCount)
marker := "(will be created)"
if report.OpenCodeTargetFound {
marker = "(exists)"
}
fmt.Fprintf(cmd.OutOrStdout(), " opencode config target: %s %s\n", report.OpenCodeTargetPath, marker)
fmt.Fprintf(cmd.OutOrStdout(), " provider.ocswitch preview: valid=%v\n", report.OK)
fmt.Fprintf(cmd.OutOrStdout(), " proxy bind: %s\n", report.ProxyBindAddress)
return nil
},
}
}