mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System.Linq;
|
|
using System.Text;
|
|
using Robust.Shared.Localization;
|
|
|
|
namespace Robust.Shared.Console.Commands;
|
|
|
|
internal sealed class ListCommands : LocalizedCommands
|
|
{
|
|
public override string Command => "list";
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
var filter = "";
|
|
if (args.Length == 1)
|
|
filter = args[0];
|
|
|
|
var host = (IConsoleHostInternal)shell.ConsoleHost;
|
|
|
|
var builder = new StringBuilder(Loc.GetString("cmd-list-heading"));
|
|
foreach (var command in host.AvailableCommands.Values
|
|
.Where(p => p.Command.Contains(filter) && !host.IsCommandHidden(p))
|
|
.OrderBy(c => c.Command))
|
|
{
|
|
//TODO: Make this actually check permissions.
|
|
|
|
var side = host.IsCmdServer(command) ? "S" : "C";
|
|
builder.AppendLine($"{side} {command.Command,-32}{command.Description}");
|
|
}
|
|
|
|
var message = builder.ToString().Trim(' ', '\n');
|
|
shell.WriteLine(message);
|
|
}
|
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-list-arg-filter"));
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|