using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; using Robust.Shared.Toolshed; namespace Robust.Shared.Console { /// /// Basic interface to handle console commands. Any class implementing this will be /// registered with the console system through reflection. /// /// /// For server commands, it is much preferred to use . /// [UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public interface IConsoleCommand { /// /// Name of the command. /// /// /// A string as identifier for this command. /// string Command { get; } /// /// Short description of the command. /// /// /// String printed as short summary in the "help" command. /// string Description { get; } /// /// Extended description for the command. /// /// /// String printed as summary when "help Command" is used. /// string Help { get; } /// /// If true, this command will be unavailable to clients while they are connected to a server. Has no effect on servers. /// bool RequireServerOrSingleplayer => false; /// /// Executes the client command. /// /// The console that executed this command. /// Unparsed text of the complete command with arguments. /// An array of all the parsed arguments. void Execute(IConsoleShell shell, string argStr, string[] args); /// /// Fetches completion results for a typing a command. /// /// /// /// Refrain from doing simple .StartsWith( filtering based on the currently typing command. /// The client already does this filtering on its own, /// so doing it manually would reduce responsiveness thanks to network lag. /// It may however be desirable to do larger-scale filtering. /// For example when typing out a resource path you could manually filter level-by-level as it's being typed. /// /// /// Only arguments to the left of the cursor are passed. /// If the user puts their cursor in the middle of a line and starts typing, anything to the right is ignored. /// /// /// The console that is typing this command. /// The set of commands currently being typed. /// If the last parameter is an empty string, it basically represents that the user hit space after the previous term and should already get completion results, /// even if they haven't started typing the new argument yet. /// The possible completion results presented to the user. /// CompletionResult GetCompletion(IConsoleShell shell, string[] args) => CompletionResult.Empty; /// /// Fetches completion results for typing a command, async variant. See for details. /// /// /// If this method is implemented, will not be automatically called. /// ValueTask GetCompletionAsync(IConsoleShell shell, string[] args, string argStr, CancellationToken cancel) { return ValueTask.FromResult(GetCompletion(shell, args)); } } /// /// Special marker interface used to indicate "entity" commands. /// See for an overview. /// /// internal interface IEntityConsoleCommand : IConsoleCommand; }