|
2 | 2 | package doctor |
3 | 3 |
|
4 | 4 | import ( |
5 | | - "errors" |
6 | | - "fmt" |
7 | | - |
8 | 5 | "forge.lthn.ai/core/cli/pkg/cli" |
9 | 6 | "forge.lthn.ai/core/go-i18n" |
10 | 7 | "github.com/spf13/cobra" |
@@ -32,89 +29,89 @@ func init() { |
32 | 29 | } |
33 | 30 |
|
34 | 31 | func runDoctor(verbose bool) error { |
35 | | - fmt.Println(i18n.T("common.progress.checking", map[string]any{"Item": "development environment"})) |
36 | | - fmt.Println() |
| 32 | + cli.Println("%s", i18n.T("common.progress.checking", map[string]any{"Item": "development environment"})) |
| 33 | + cli.Blank() |
37 | 34 |
|
38 | 35 | var passed, failed, optional int |
39 | 36 |
|
40 | 37 | // Check required tools |
41 | | - fmt.Println(i18n.T("cmd.doctor.required")) |
42 | | - for _, c := range requiredChecks() { |
43 | | - ok, version := runCheck(c) |
| 38 | + cli.Println("%s", i18n.T("cmd.doctor.required")) |
| 39 | + for _, toolCheck := range requiredChecks() { |
| 40 | + ok, version := runCheck(toolCheck) |
44 | 41 | if ok { |
45 | 42 | if verbose { |
46 | | - fmt.Println(formatCheckResult(true, c.name, version)) |
| 43 | + cli.Println("%s", formatCheckResult(true, toolCheck.name, version)) |
47 | 44 | } else { |
48 | | - fmt.Println(formatCheckResult(true, c.name, "")) |
| 45 | + cli.Println("%s", formatCheckResult(true, toolCheck.name, "")) |
49 | 46 | } |
50 | 47 | passed++ |
51 | 48 | } else { |
52 | | - fmt.Printf(" %s %s - %s\n", errorStyle.Render(cli.Glyph(":cross:")), c.name, c.description) |
| 49 | + cli.Println(" %s %s - %s", errorStyle.Render(cli.Glyph(":cross:")), toolCheck.name, toolCheck.description) |
53 | 50 | failed++ |
54 | 51 | } |
55 | 52 | } |
56 | 53 |
|
57 | 54 | // Check optional tools |
58 | | - fmt.Printf("\n%s\n", i18n.T("cmd.doctor.optional")) |
59 | | - for _, c := range optionalChecks() { |
60 | | - ok, version := runCheck(c) |
| 55 | + cli.Println("\n%s", i18n.T("cmd.doctor.optional")) |
| 56 | + for _, toolCheck := range optionalChecks() { |
| 57 | + ok, version := runCheck(toolCheck) |
61 | 58 | if ok { |
62 | 59 | if verbose { |
63 | | - fmt.Println(formatCheckResult(true, c.name, version)) |
| 60 | + cli.Println("%s", formatCheckResult(true, toolCheck.name, version)) |
64 | 61 | } else { |
65 | | - fmt.Println(formatCheckResult(true, c.name, "")) |
| 62 | + cli.Println("%s", formatCheckResult(true, toolCheck.name, "")) |
66 | 63 | } |
67 | 64 | passed++ |
68 | 65 | } else { |
69 | | - fmt.Printf(" %s %s - %s\n", dimStyle.Render(cli.Glyph(":skip:")), c.name, dimStyle.Render(c.description)) |
| 66 | + cli.Println(" %s %s - %s", dimStyle.Render(cli.Glyph(":skip:")), toolCheck.name, dimStyle.Render(toolCheck.description)) |
70 | 67 | optional++ |
71 | 68 | } |
72 | 69 | } |
73 | 70 |
|
74 | 71 | // Check GitHub access |
75 | | - fmt.Printf("\n%s\n", i18n.T("cmd.doctor.github")) |
| 72 | + cli.Println("\n%s", i18n.T("cmd.doctor.github")) |
76 | 73 | if checkGitHubSSH() { |
77 | | - fmt.Println(formatCheckResult(true, i18n.T("cmd.doctor.ssh_found"), "")) |
| 74 | + cli.Println("%s", formatCheckResult(true, i18n.T("cmd.doctor.ssh_found"), "")) |
78 | 75 | } else { |
79 | | - fmt.Printf(" %s %s\n", errorStyle.Render(cli.Glyph(":cross:")), i18n.T("cmd.doctor.ssh_missing")) |
| 76 | + cli.Println(" %s %s", errorStyle.Render(cli.Glyph(":cross:")), i18n.T("cmd.doctor.ssh_missing")) |
80 | 77 | failed++ |
81 | 78 | } |
82 | 79 |
|
83 | 80 | if checkGitHubCLI() { |
84 | | - fmt.Println(formatCheckResult(true, i18n.T("cmd.doctor.cli_auth"), "")) |
| 81 | + cli.Println("%s", formatCheckResult(true, i18n.T("cmd.doctor.cli_auth"), "")) |
85 | 82 | } else { |
86 | | - fmt.Printf(" %s %s\n", errorStyle.Render(cli.Glyph(":cross:")), i18n.T("cmd.doctor.cli_auth_missing")) |
| 83 | + cli.Println(" %s %s", errorStyle.Render(cli.Glyph(":cross:")), i18n.T("cmd.doctor.cli_auth_missing")) |
87 | 84 | failed++ |
88 | 85 | } |
89 | 86 |
|
90 | 87 | // Check workspace |
91 | | - fmt.Printf("\n%s\n", i18n.T("cmd.doctor.workspace")) |
| 88 | + cli.Println("\n%s", i18n.T("cmd.doctor.workspace")) |
92 | 89 | checkWorkspace() |
93 | 90 |
|
94 | 91 | // Summary |
95 | | - fmt.Println() |
| 92 | + cli.Blank() |
96 | 93 | if failed > 0 { |
97 | 94 | cli.Error(i18n.T("cmd.doctor.issues", map[string]any{"Count": failed})) |
98 | | - fmt.Printf("\n%s\n", i18n.T("cmd.doctor.install_missing")) |
| 95 | + cli.Println("\n%s", i18n.T("cmd.doctor.install_missing")) |
99 | 96 | printInstallInstructions() |
100 | | - return errors.New(i18n.T("cmd.doctor.issues_error", map[string]any{"Count": failed})) |
| 97 | + return cli.Err("%s", i18n.T("cmd.doctor.issues_error", map[string]any{"Count": failed})) |
101 | 98 | } |
102 | 99 |
|
103 | 100 | cli.Success(i18n.T("cmd.doctor.ready")) |
104 | 101 | return nil |
105 | 102 | } |
106 | 103 |
|
107 | 104 | func formatCheckResult(ok bool, name, detail string) string { |
108 | | - check := cli.Check(name) |
| 105 | + checkBuilder := cli.Check(name) |
109 | 106 | if ok { |
110 | | - check.Pass() |
| 107 | + checkBuilder.Pass() |
111 | 108 | } else { |
112 | | - check.Fail() |
| 109 | + checkBuilder.Fail() |
113 | 110 | } |
114 | 111 | if detail != "" { |
115 | | - check.Message(detail) |
| 112 | + checkBuilder.Message(detail) |
116 | 113 | } else { |
117 | | - check.Message("") |
| 114 | + checkBuilder.Message("") |
118 | 115 | } |
119 | | - return check.String() |
| 116 | + return checkBuilder.String() |
120 | 117 | } |
0 commit comments