// Khaemhat.DataModelTool: writes the generated section of docs/DATA-MODEL.md from the migrations (SPEC §18). // dotnet run --project tools/Khaemhat.DataModelTool -- [--check] [path/to/DATA-MODEL.md] // With --check it changes nothing and exits with 1 when the document is out of date (used by CI and tests). using System.Text; using Khaemhat.Data.Migrations; var check = args.Contains("--check"); var path = args.FirstOrDefault(a => !a.StartsWith("--", StringComparison.Ordinal)) ?? Path.Combine("docs", "DATA-MODEL.md"); if (!File.Exists(path)) { Console.Error.WriteLine($"DataModelTool: file non trovato: {path}"); return 2; } var current = File.ReadAllText(path, Encoding.UTF8); var updated = DataModelDocument.Update(current, DataModelDocument.Render(MigrationCatalog.ForSystem(), MigrationCatalog.ForCompany())); if (string.Equals(current, updated, StringComparison.Ordinal)) { Console.WriteLine($"DataModelTool: {path} è aggiornato."); return 0; } if (check) { Console.Error.WriteLine($"DataModelTool: {path} non è aggiornato: eseguire scripts/gen-datamodel.sh."); return 1; } File.WriteAllText(path, updated, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); Console.WriteLine($"DataModelTool: {path} rigenerato."); return 0;