noz-cli/Noz.PowerShell/Cmdlets/NewNozNoteCmdlet.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

59 lines
1.6 KiB
C#

using System.Management.Automation;
namespace Noz.PowerShell.Cmdlets;
/// <summary>Create a new note on the server.</summary>
/// <example>
/// New-NozNote -Slug psychologie/neue-notiz -Title "Neue Notiz"
/// New-NozNote -Slug biosysteme/pilze -Title "Pilze" -Topic biosysteme -Status budding -Lang de
/// </example>
[Cmdlet(VerbsCommon.New, "NozNote", SupportsShouldProcess = true)]
[OutputType(typeof(NozNote))]
public sealed class NewNozNoteCmdlet : NozCmdletBase
{
[Parameter(Mandatory = true, Position = 0)]
public string Slug { get; set; } = "";
[Parameter(Mandatory = true, Position = 1)]
public string Title { get; set; } = "";
[Parameter]
public string? Topic { get; set; }
[Parameter]
[ValidateSet("seed", "budding", "evergreen")]
public string Status { get; set; } = "seed";
[Parameter]
[ValidateSet("de", "en")]
public string Lang { get; set; } = "de";
[Parameter]
public string Description { get; set; } = "";
protected override void ProcessRecord()
{
if (!ShouldProcess(Slug, "Create note")) return;
var topic = Topic ?? (Slug.Contains('/') ? Slug.Split('/')[0] : Slug);
var markdown = $"""
---
title: "{Title}"
description: "{Description}"
topic: {topic}
status: {Status}
lang: {Lang}
---
# {Title}
""";
Run(Api.PutNoteAsync(Slug, markdown));
var notes = Run(Api.GetNotesAsync());
var created = notes.FirstOrDefault(n => n.Slug == Slug);
if (created is not null)
WriteObject(NozNote.From(created));
}
}