using System.Management.Automation; namespace Noz.PowerShell.Cmdlets; /// Update the markdown content of an existing note. /// /// Set-NozNote -Slug psychologie/test -Markdown "# Test`n`nHello." /// Get-Content note.md -Raw | Set-NozNote -Slug psychologie/test /// [Cmdlet(VerbsCommon.Set, "NozNote", SupportsShouldProcess = true)] [OutputType(typeof(NozNote))] public sealed class SetNozNoteCmdlet : NozCmdletBase { [Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)] public string Slug { get; set; } = ""; [Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true)] public string Markdown { get; set; } = ""; protected override void ProcessRecord() { if (!ShouldProcess(Slug, "Update note")) return; Run(Api.PutNoteAsync(Slug, Markdown)); var notes = Run(Api.GetNotesAsync()); var updated = notes.FirstOrDefault(n => n.Slug == Slug); if (updated is not null) WriteObject(NozNote.From(updated)); } }