|
| 1 | +using System.CommandLine; |
| 2 | + |
| 3 | +namespace ClawSharp.Cli.Commands; |
| 4 | + |
| 5 | +public class DoctorCommand : Command |
| 6 | +{ |
| 7 | + public DoctorCommand() : base("doctor", "Run diagnostics") |
| 8 | + { |
| 9 | + SetAction(_ => Execute()); |
| 10 | + } |
| 11 | + |
| 12 | + private static void Execute() |
| 13 | + { |
| 14 | + Console.WriteLine(" ClawSharp Doctor"); |
| 15 | + Console.WriteLine(" ================"); |
| 16 | + |
| 17 | + var checks = new List<(string Name, bool Pass, string Detail)>(); |
| 18 | + |
| 19 | + var homePath = Path.Combine( |
| 20 | + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".clawsharp"); |
| 21 | + |
| 22 | + var configPath = Environment.GetEnvironmentVariable("CLAWSHARP_CONFIG_PATH") |
| 23 | + ?? Path.Combine(homePath, "config.toml"); |
| 24 | + checks.Add(("Config file", File.Exists(configPath), configPath)); |
| 25 | + |
| 26 | + checks.Add(("Data directory", Directory.Exists(homePath), homePath)); |
| 27 | + |
| 28 | + var workspacePath = Path.Combine(homePath, "workspace"); |
| 29 | + checks.Add(("Workspace directory", Directory.Exists(workspacePath), workspacePath)); |
| 30 | + |
| 31 | + // SQLite check |
| 32 | + try |
| 33 | + { |
| 34 | + using var conn = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:"); |
| 35 | + conn.Open(); |
| 36 | + checks.Add(("SQLite", true, "Available")); |
| 37 | + } |
| 38 | + catch (Exception ex) |
| 39 | + { |
| 40 | + checks.Add(("SQLite", false, ex.Message)); |
| 41 | + } |
| 42 | + |
| 43 | + foreach (var (name, pass, detail) in checks) |
| 44 | + { |
| 45 | + var icon = pass ? "✅" : "❌"; |
| 46 | + Console.WriteLine($" {icon} {name}: {detail}"); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments