explicitly make ICommandInfo => IReadOnlyCommandInfo

This commit is contained in:
goat 2024-06-28 23:26:15 +02:00
parent 29f951c309
commit d628be9536
3 changed files with 21 additions and 21 deletions

View file

@ -3,20 +3,20 @@ namespace Dalamud.Game.Command;
/// <summary>
/// This class describes a registered command.
/// </summary>
public sealed class CommandInfo : ICommandInfo
public sealed class CommandInfo : IReadOnlyCommandInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="CommandInfo"/> class.
/// Create a new CommandInfo with the provided handler.
/// </summary>
/// <param name="handler">The method to call when the command is run.</param>
public CommandInfo(ICommandInfo.HandlerDelegate handler)
public CommandInfo(IReadOnlyCommandInfo.HandlerDelegate handler)
{
this.Handler = handler;
}
/// <inheritdoc/>
public ICommandInfo.HandlerDelegate Handler { get; }
public IReadOnlyCommandInfo.HandlerDelegate Handler { get; }
/// <inheritdoc/>
public string HelpMessage { get; set; } = string.Empty;
@ -28,7 +28,7 @@ public sealed class CommandInfo : ICommandInfo
/// <summary>
/// Interface representing a registered command.
/// </summary>
public interface ICommandInfo
public interface IReadOnlyCommandInfo
{
/// <summary>
/// The function to be executed when the command is dispatched.
@ -43,12 +43,12 @@ public interface ICommandInfo
HandlerDelegate Handler { get; }
/// <summary>
/// Gets or sets the help message for this command.
/// Gets the help message for this command.
/// </summary>
string HelpMessage { get; set; }
string HelpMessage { get; }
/// <summary>
/// Gets or sets a value indicating whether if this command should be shown in the help output.
/// Gets a value indicating whether if this command should be shown in the help output.
/// </summary>
bool ShowInHelp { get; set; }
bool ShowInHelp { get; }
}

View file

@ -24,8 +24,8 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
{
private static readonly ModuleLog Log = new("Command");
private readonly ConcurrentDictionary<string, ICommandInfo> commandMap = new();
private readonly ConcurrentDictionary<(string, ICommandInfo), string> commandAssemblyNameMap = new();
private readonly ConcurrentDictionary<string, IReadOnlyCommandInfo> commandMap = new();
private readonly ConcurrentDictionary<(string, IReadOnlyCommandInfo), string> commandAssemblyNameMap = new();
private readonly Regex commandRegexEn = new(@"^The command (?<command>.+) does not exist\.$", RegexOptions.Compiled);
private readonly Regex commandRegexJp = new(@"^そのコマンドはありません。: (?<command>.+)$", RegexOptions.Compiled);
private readonly Regex commandRegexDe = new(@"^„(?<command>.+)“ existiert nicht als Textkommando\.$", RegexOptions.Compiled);
@ -56,7 +56,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
}
/// <inheritdoc/>
public ReadOnlyDictionary<string, ICommandInfo> Commands => new(this.commandMap);
public ReadOnlyDictionary<string, IReadOnlyCommandInfo> Commands => new(this.commandMap);
/// <inheritdoc/>
public bool ProcessCommand(string content)
@ -102,7 +102,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
}
/// <inheritdoc/>
public void DispatchCommand(string command, string argument, ICommandInfo info)
public void DispatchCommand(string command, string argument, IReadOnlyCommandInfo info)
{
try
{
@ -115,7 +115,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
}
/// <inheritdoc/>
public bool AddHandler(string command, ICommandInfo info, string loaderAssemblyName = "")
public bool AddHandler(string command, CommandInfo info, string loaderAssemblyName = "")
{
if (info == null)
throw new ArgumentNullException(nameof(info), "Command handler is null.");
@ -137,7 +137,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
}
/// <inheritdoc/>
public bool AddHandler(string command, ICommandInfo info)
public bool AddHandler(string command, CommandInfo info)
{
if (info == null)
throw new ArgumentNullException(nameof(info), "Command handler is null.");
@ -163,7 +163,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
/// <param name="command">The command.</param>
/// <param name="commandInfo">A ICommandInfo object.</param>
/// <returns>The name of the assembly.</returns>
public string GetHandlerAssemblyName(string command, ICommandInfo commandInfo)
public string GetHandlerAssemblyName(string command, IReadOnlyCommandInfo commandInfo)
{
if (this.commandAssemblyNameMap.TryGetValue((command, commandInfo), out var assemblyName))
{
@ -178,7 +178,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
/// </summary>
/// <param name="assemblyName">The name of the assembly.</param>
/// <returns>A list of commands and their associated activation string.</returns>
public List<KeyValuePair<(string, ICommandInfo), string>> GetHandlersByAssemblyName(string assemblyName)
public List<KeyValuePair<(string, IReadOnlyCommandInfo), string>> GetHandlersByAssemblyName(string assemblyName)
{
return this.commandAssemblyNameMap.Where(c => c.Value == assemblyName).ToList();
}
@ -249,7 +249,7 @@ internal class CommandManagerPluginScoped : IInternalDisposableService, ICommand
}
/// <inheritdoc/>
public ReadOnlyDictionary<string, ICommandInfo> Commands => this.commandManagerService.Commands;
public ReadOnlyDictionary<string, IReadOnlyCommandInfo> Commands => this.commandManagerService.Commands;
/// <inheritdoc/>
void IInternalDisposableService.DisposeService()
@ -267,11 +267,11 @@ internal class CommandManagerPluginScoped : IInternalDisposableService, ICommand
=> this.commandManagerService.ProcessCommand(content);
/// <inheritdoc/>
public void DispatchCommand(string command, string argument, ICommandInfo info)
public void DispatchCommand(string command, string argument, IReadOnlyCommandInfo info)
=> this.commandManagerService.DispatchCommand(command, argument, info);
/// <inheritdoc/>
public bool AddHandler(string command, ICommandInfo info)
public bool AddHandler(string command, CommandInfo info)
{
if (!this.pluginRegisteredCommands.Contains(command))
{

View file

@ -12,7 +12,7 @@ public interface ICommandManager
/// <summary>
/// Gets a read-only list of all registered commands.
/// </summary>
public ReadOnlyDictionary<string, ICommandInfo> Commands { get; }
public ReadOnlyDictionary<string, IReadOnlyCommandInfo> Commands { get; }
/// <summary>
/// Process a command in full.
@ -27,7 +27,7 @@ public interface ICommandManager
/// <param name="command">The command to dispatch.</param>
/// <param name="argument">The provided arguments.</param>
/// <param name="info">A <see cref="CommandInfo"/> object describing this command.</param>
public void DispatchCommand(string command, string argument, CommandInfo info);
public void DispatchCommand(string command, string argument, IReadOnlyCommandInfo info);
/// <summary>
/// Add a command handler, which you can use to add your own custom commands to the in-game chat.