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.
31 lines
1,023 B
C#
31 lines
1,023 B
C#
using NozCli.Rendering;
|
|
using NozCli.Repl;
|
|
using Spectre.Console;
|
|
|
|
namespace NozCli.Commands;
|
|
|
|
public class CatCommand : ICommand
|
|
{
|
|
public string Name => "cat";
|
|
public string Description => "Print a note — rendered by default, --raw for plain markdown";
|
|
public string Usage => "cat [--raw] <slug>";
|
|
|
|
public async Task ExecuteAsync(string[] args, ReplContext ctx, CancellationToken ct = default)
|
|
{
|
|
var raw = args.Contains("--raw") || args.Contains("-r");
|
|
var slug = args.FirstOrDefault(a => !a.StartsWith('-'));
|
|
|
|
if (slug is null) { AnsiConsole.MarkupLine("[red]Usage: cat [--raw] <slug>[/]"); return; }
|
|
|
|
slug = ctx.ResolveSlug(slug);
|
|
|
|
Core.Models.NoteContent note = default!;
|
|
await AnsiConsole.Status().StartAsync("Fetching…", async _ =>
|
|
note = await ctx.Api.GetNoteAsync(slug, ct));
|
|
|
|
if (raw)
|
|
AnsiConsole.WriteLine(note.Markdown);
|
|
else
|
|
MarkdownRenderer.Render(note.Markdown);
|
|
}
|
|
}
|