using System.Management.Automation; namespace Noz.PowerShell.Cmdlets; [Cmdlet(VerbsDiagnostic.Measure, "NozGarden")] [OutputType(typeof(NozGardenStats))] public sealed class MeasureNozGardenCmdlet : NozCmdletBase { protected override void ProcessRecord() { var notesTask = Api.GetNotesAsync(); var graphTask = Api.GetGraphAsync(); var notes = Run(notesTask); var graph = Run(graphTask); var targets = new HashSet(graph.Edges.Select(e => e.Target)); var orphans = notes.Count(n => !targets.Contains(n.Slug)); var byTopic = notes .GroupBy(n => n.Topic ?? "—") .ToDictionary(g => g.Key, g => g.Count()); var byLang = notes .GroupBy(n => n.Lang) .ToDictionary(g => g.Key, g => g.Count()); WriteObject(new NozGardenStats { TotalNotes = notes.Count, SeedCount = notes.Count(n => n.Status == "seed"), BuddingCount = notes.Count(n => n.Status == "budding"), EvergreenCount = notes.Count(n => n.Status == "evergreen"), TopicCount = byTopic.Count, LinkCount = graph.Edges.Count, OrphanCount = orphans, NotesByTopic = byTopic, NotesByLang = byLang, }); } }