using System.Management.Automation; namespace Noz.PowerShell.Cmdlets; [Cmdlet(VerbsCommon.Get, "NozGraph")] [OutputType(typeof(NozGraphEdge))] public sealed class GetNozGraphCmdlet : NozCmdletBase { [Parameter] public string? Source { get; set; } [Parameter] public string? Target { get; set; } protected override void ProcessRecord() { var graph = Run(Api.GetGraphAsync()); var nodeMap = graph.Nodes.ToDictionary(n => n.Id, n => n.Title); var edges = graph.Edges.AsEnumerable(); if (Source is not null) edges = edges.Where(e => e.Source.Contains(Source, StringComparison.OrdinalIgnoreCase)); if (Target is not null) edges = edges.Where(e => e.Target.Contains(Target, StringComparison.OrdinalIgnoreCase)); foreach (var e in edges) { WriteObject(new NozGraphEdge { Source = e.Source, Target = e.Target, SourceTitle = nodeMap.GetValueOrDefault(e.Source, e.Source), TargetTitle = nodeMap.GetValueOrDefault(e.Target, e.Target), }); } } }