initial commit
This commit is contained in:
33
Commands/HelpCommand.cs
Normal file
33
Commands/HelpCommand.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Spectre.Console;
|
||||
using System.Linq;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user