- ls: compact view with status dots and folder markers - ls -la: table view with status, lang, date, title; folders show mini status bar - tree: recursive hierarchy using Spectre.Console Tree widget, context-aware - All commands: CancellationToken threaded through ExecuteAsync - Partition() helper respects topic-relative slug depth
34 lines
885 B
C#
34 lines
885 B
C#
using NozCli.Repl;
|
|
using Spectre.Console;
|
|
|
|
namespace NozCli.Commands;
|
|
|
|
public class CdCommand : ICommand
|
|
{
|
|
public string Name => "cd";
|
|
public string Description => "Navigate into a topic or folder";
|
|
public string Usage => "cd <folder> | cd .. | cd ~";
|
|
|
|
public Task ExecuteAsync(string[] args, ReplContext ctx, CancellationToken ct = default)
|
|
{
|
|
var target = args.FirstOrDefault()?.TrimEnd('/');
|
|
|
|
if (target is null or "~")
|
|
{
|
|
ctx.CurrentTopic = null;
|
|
ctx.CurrentSubPath = null;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
if (target == "..")
|
|
{
|
|
ctx.NavigateUp();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
if (!ctx.NavigateTo(target))
|
|
AnsiConsole.MarkupLine($"[red]cd: {target}: no such folder[/]");
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|