32 lines
900 B
C#
32 lines
900 B
C#
using Spectre.Console;
|
|
|
|
namespace AnchorCli.Commands;
|
|
|
|
internal class LoadCommand(ChatSession session) : ICommand
|
|
{
|
|
public string Name => "load";
|
|
public string Description => "Load a chat session from a file";
|
|
|
|
public async Task ExecuteAsync(string[] args, CancellationToken ct)
|
|
{
|
|
string filePath = args.Length > 0 ? args[0] : ".anchor/session.json";
|
|
|
|
if (!File.Exists(filePath))
|
|
{
|
|
AnsiConsole.MarkupLine($"[yellow]No session file found at {Markup.Escape(filePath)}[/]");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
await session.LoadAsync(filePath, ct);
|
|
AnsiConsole.MarkupLine($"[green]Session loaded from {Markup.Escape(filePath)}[/]");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
AnsiConsole.MarkupLine($"[red]Failed to load session: {Markup.Escape(ex.Message)}[/]");
|
|
}
|
|
}
|
|
}
|
|
|