36 lines
1007 B
C#
36 lines
1007 B
C#
using Spectre.Console;
|
|
using System.Reflection;
|
|
namespace AnchorCli.Commands;
|
|
|
|
public class HelpCommand : ICommand
|
|
{
|
|
private readonly CommandRegistry _registry;
|
|
|
|
public string Name => "help";
|
|
public string Description => "Show available commands";
|
|
|
|
public HelpCommand(CommandRegistry registry)
|
|
{
|
|
_registry = registry;
|
|
}
|
|
|
|
public Task ExecuteAsync(string[] args, CancellationToken ct)
|
|
{
|
|
var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
|
|
AnsiConsole.MarkupLine($"[cyan]Anchor CLI v{version}[/]");
|
|
AnsiConsole.MarkupLine("[cyan]Available commands:[/]");
|
|
|
|
var table = new Table();
|
|
table.AddColumn("Command");
|
|
table.AddColumn("Description");
|
|
|
|
foreach (var cmd in _registry.GetAllCommands().OrderBy(c => c.Name))
|
|
{
|
|
table.AddRow($"[bold]{cmd.Name}[/]", cmd.Description);
|
|
}
|
|
|
|
AnsiConsole.Write(table);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|