- 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
47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
using System.Management.Automation;
|
|
using NozCli.Core.Client;
|
|
using NozCli.Core.Config;
|
|
|
|
namespace Noz.PowerShell;
|
|
|
|
public abstract class NozCmdletBase : PSCmdlet
|
|
{
|
|
protected LocalConfig Config { get; private set; } = null!;
|
|
protected NozApiClient Api { get; private set; } = null!;
|
|
|
|
protected override void BeginProcessing()
|
|
{
|
|
var cfg = LocalConfig.Load();
|
|
if (cfg is null)
|
|
ThrowTerminatingError(new ErrorRecord(
|
|
new InvalidOperationException(
|
|
"noz is not initialized. Run: noz init <server-url> <token>"),
|
|
"NozNotInitialized",
|
|
ErrorCategory.NotSpecified,
|
|
targetObject: null));
|
|
|
|
Config = cfg!;
|
|
Api = new NozApiClient(cfg!);
|
|
}
|
|
|
|
protected override void StopProcessing() => Api?.Dispose();
|
|
|
|
protected T Run<T>(Task<T> task)
|
|
{
|
|
try { return task.GetAwaiter().GetResult(); }
|
|
catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
|
{
|
|
ThrowTerminatingError(new ErrorRecord(ex, "NozUnauthorized",
|
|
ErrorCategory.AuthenticationError, null));
|
|
throw;
|
|
}
|
|
catch (HttpRequestException ex)
|
|
{
|
|
ThrowTerminatingError(new ErrorRecord(ex, "NozApiError",
|
|
ErrorCategory.ConnectionError, null));
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected void Run(Task task) => Run(task.ContinueWith(_ => true));
|
|
}
|