noz-cli/Noz.PowerShell/Cmdlets/GetNozNoteCmdlet.cs
kryptomrx db9aabd2b7 feat(powershell): Noz PowerShell module with pipeline-native cmdlets
- Get-NozNote: list notes, filter by -Topic, -Status, -Lang
- Get-NozNoteContent: fetch markdown, accepts pipeline input by Slug
- Set-NozNote: update note content, accepts markdown from pipeline
- New-NozNote: create note with frontmatter template
- Remove-NozNote: delete note, ShouldProcess + ConfirmImpact.High for safety
- NozNote output object: clean PS-friendly properties (no internal Hash field)
- NozCmdletBase: shared config loading, API client lifecycle, error translation
- Noz.psd1: module manifest for PS 7.2+
- Install-NozModule.ps1: build + install to user module path
- NozCli.Core retargeted to net8.0 for PS 7.4 LTS compatibility
2026-05-16 23:42:27 +02:00

41 lines
1.2 KiB
C#

using System.Management.Automation;
namespace Noz.PowerShell.Cmdlets;
/// <summary>List notes from the noz server.</summary>
/// <example>
/// Get-NozNote
/// Get-NozNote -Topic psychologie
/// Get-NozNote -Status seed -Lang de
/// Get-NozNote | Group-Object Topic | Sort-Object Count -Descending
/// Get-NozNote | Export-Csv ~/notes.csv
/// </example>
[Cmdlet(VerbsCommon.Get, "NozNote")]
[OutputType(typeof(NozNote))]
public sealed class GetNozNoteCmdlet : NozCmdletBase
{
[Parameter(Position = 0)]
public string? Topic { get; set; }
[Parameter]
[ValidateSet("seed", "budding", "evergreen")]
public string? Status { get; set; }
[Parameter]
[ValidateSet("de", "en")]
public string? Lang { get; set; }
protected override void ProcessRecord()
{
var notes = Run(Api.GetNotesAsync());
var filtered = notes.AsEnumerable();
if (Topic is not null) filtered = filtered.Where(n => n.Topic == Topic);
if (Status is not null) filtered = filtered.Where(n => n.Status == Status);
if (Lang is not null) filtered = filtered.Where(n => n.Lang == Lang);
foreach (var note in filtered.OrderBy(n => n.Slug))
WriteObject(NozNote.From(note));
}
}