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> /// <summary>
/// This class describes a registered command. /// This class describes a registered command.
/// </summary> /// </summary>
public sealed class CommandInfo : ICommandInfo public sealed class CommandInfo : IReadOnlyCommandInfo
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CommandInfo"/> class. /// Initializes a new instance of the <see cref="CommandInfo"/> class.
/// Create a new CommandInfo with the provided handler. /// Create a new CommandInfo with the provided handler.
/// </summary> /// </summary>
/// <param name="handler">The method to call when the command is run.</param> /// <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; this.Handler = handler;
} }
/// <inheritdoc/> /// <inheritdoc/>
public ICommandInfo.HandlerDelegate Handler { get; } public IReadOnlyCommandInfo.HandlerDelegate Handler { get; }
/// <inheritdoc/> /// <inheritdoc/>
public string HelpMessage { get; set; } = string.Empty; public string HelpMessage { get; set; } = string.Empty;
@ -28,7 +28,7 @@ public sealed class CommandInfo : ICommandInfo
/// <summary> /// <summary>
/// Interface representing a registered command. /// Interface representing a registered command.
/// </summary> /// </summary>
public interface ICommandInfo public interface IReadOnlyCommandInfo
{ {
/// <summary> /// <summary>
/// The function to be executed when the command is dispatched. /// The function to be executed when the command is dispatched.
@ -43,12 +43,12 @@ public interface ICommandInfo
HandlerDelegate Handler { get; } HandlerDelegate Handler { get; }
/// <summary> /// <summary>
/// Gets or sets the help message for this command. /// Gets the help message for this command.
/// </summary> /// </summary>
string HelpMessage { get; set; } string HelpMessage { get; }
/// <summary> /// <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> /// </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 static readonly ModuleLog Log = new("Command");
private readonly ConcurrentDictionary<string, ICommandInfo> commandMap = new(); private readonly ConcurrentDictionary<string, IReadOnlyCommandInfo> commandMap = new();
private readonly ConcurrentDictionary<(string, ICommandInfo), string> commandAssemblyNameMap = 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 commandRegexEn = new(@"^The command (?<command>.+) does not exist\.$", RegexOptions.Compiled);
private readonly Regex commandRegexJp = new(@"^そのコマンドはありません。: (?<command>.+)$", RegexOptions.Compiled); private readonly Regex commandRegexJp = new(@"^そのコマンドはありません。: (?<command>.+)$", RegexOptions.Compiled);
private readonly Regex commandRegexDe = new(@"^„(?<command>.+)“ existiert nicht als Textkommando\.$", 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/> /// <inheritdoc/>
public ReadOnlyDictionary<string, ICommandInfo> Commands => new(this.commandMap); public ReadOnlyDictionary<string, IReadOnlyCommandInfo> Commands => new(this.commandMap);
/// <inheritdoc/> /// <inheritdoc/>
public bool ProcessCommand(string content) public bool ProcessCommand(string content)
@ -102,7 +102,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
} }
/// <inheritdoc/> /// <inheritdoc/>
public void DispatchCommand(string command, string argument, ICommandInfo info) public void DispatchCommand(string command, string argument, IReadOnlyCommandInfo info)
{ {
try try
{ {
@ -115,7 +115,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool AddHandler(string command, ICommandInfo info, string loaderAssemblyName = "") public bool AddHandler(string command, CommandInfo info, string loaderAssemblyName = "")
{ {
if (info == null) if (info == null)
throw new ArgumentNullException(nameof(info), "Command handler is null."); throw new ArgumentNullException(nameof(info), "Command handler is null.");
@ -137,7 +137,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool AddHandler(string command, ICommandInfo info) public bool AddHandler(string command, CommandInfo info)
{ {
if (info == null) if (info == null)
throw new ArgumentNullException(nameof(info), "Command handler is 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="command">The command.</param>
/// <param name="commandInfo">A ICommandInfo object.</param> /// <param name="commandInfo">A ICommandInfo object.</param>
/// <returns>The name of the assembly.</returns> /// <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)) if (this.commandAssemblyNameMap.TryGetValue((command, commandInfo), out var assemblyName))
{ {
@ -178,7 +178,7 @@ internal sealed class CommandManager : IInternalDisposableService, ICommandManag
/// </summary> /// </summary>
/// <param name="assemblyName">The name of the assembly.</param> /// <param name="assemblyName">The name of the assembly.</param>
/// <returns>A list of commands and their associated activation string.</returns> /// <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(); return this.commandAssemblyNameMap.Where(c => c.Value == assemblyName).ToList();
} }
@ -249,7 +249,7 @@ internal class CommandManagerPluginScoped : IInternalDisposableService, ICommand
} }
/// <inheritdoc/> /// <inheritdoc/>
public ReadOnlyDictionary<string, ICommandInfo> Commands => this.commandManagerService.Commands; public ReadOnlyDictionary<string, IReadOnlyCommandInfo> Commands => this.commandManagerService.Commands;
/// <inheritdoc/> /// <inheritdoc/>
void IInternalDisposableService.DisposeService() void IInternalDisposableService.DisposeService()
@ -267,11 +267,11 @@ internal class CommandManagerPluginScoped : IInternalDisposableService, ICommand
=> this.commandManagerService.ProcessCommand(content); => this.commandManagerService.ProcessCommand(content);
/// <inheritdoc/> /// <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); => this.commandManagerService.DispatchCommand(command, argument, info);
/// <inheritdoc/> /// <inheritdoc/>
public bool AddHandler(string command, ICommandInfo info) public bool AddHandler(string command, CommandInfo info)
{ {
if (!this.pluginRegisteredCommands.Contains(command)) if (!this.pluginRegisteredCommands.Contains(command))
{ {

View file

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