noz-cli/NozCli/Commands/TemplatesCommand.cs
kryptomrx 58410f8d9f feat: link and templates commands with note linking helper
NoteLinkHelper inserts wikilinks into an existing 'Siehe auch' section
or appends one. ApplyPlaceholders fills {{title}}/{{date}}/{{topic}} in
template bodies. new --template <name> fetches a server-side template
before opening the editor. SlugGuard moved to NozCli.Core in a previous
session — remove stale copy from NozCli.
2026-05-17 00:28:22 +02:00

39 lines
1.3 KiB
C#

using NozCli.Repl;
using Spectre.Console;
namespace NozCli.Commands;
public class TemplatesCommand : ICommand
{
public string Name => "templates";
public string Description => "List available note templates";
public string Usage => "templates";
public async Task ExecuteAsync(string[] args, ReplContext ctx, CancellationToken ct = default)
{
List<NozCli.Core.Models.TemplateInfo> templates = [];
await AnsiConsole.Status().StartAsync("Lade Templates…", async _ =>
templates = await ctx.Api.GetTemplatesAsync(ct));
if (templates.Count == 0)
{
AnsiConsole.MarkupLine("[dim]Keine Templates vorhanden.[/]");
AnsiConsole.MarkupLine("[dim]Lege Templates in [white]content/noosphere/_templates/<name>.md[/] an.[/]");
return;
}
var table = new Table()
.AddColumn("[dim]Name[/]")
.AddColumn("[dim]Beschreibung[/]")
.Border(TableBorder.None)
.HideHeaders();
foreach (var t in templates.OrderBy(t => t.Name))
table.AddRow(
$"[cyan]{Markup.Escape(t.Name)}[/]",
Markup.Escape(t.Description ?? "—"));
AnsiConsole.Write(table);
AnsiConsole.MarkupLine($"[dim]Verwenden mit:[/] [white]new --template <name> <notiz-name>[/]");
}
}