TextRPG/commands/HelpCommand.cs

37 lines
1.1 KiB
C#

using System;
using TextRPG.Commands;
namespace TextRPG.Commands
{
public class HelpCommand : Command
{
public override string Name => "help";
public override string Description => "Shows available commands";
public override string Usage => "help [command]";
public override void Execute(string[] args, Action<string> outputCallback)
{
if (args.Length > 0)
{
var command = ConsoleManager.GetCommand(args[0]);
if (command != null)
{
outputCallback($"{command.Name} - {command.Description}");
outputCallback($"Usage: {command.Usage}");
}
else
{
outputCallback($"Unknown command: {args[0]}");
}
}
else
{
outputCallback("Available commands:");
foreach (var cmd in ConsoleManager.GetAllCommands())
{
outputCallback($" {cmd.Name,-10} - {cmd.Description}");
}
}
}
}
}