Switched to dependency injection for console use.
Created interfaces for input and output for better structure and easier testing.
This commit is contained in:
@@ -9,9 +9,9 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands
|
||||
help = "Clears the console.";
|
||||
}
|
||||
|
||||
public override void Run(string[] arguments = null)
|
||||
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null)
|
||||
{
|
||||
Console.Clear();
|
||||
userOutput.ClearOutput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,16 +13,16 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands
|
||||
}
|
||||
|
||||
|
||||
public override void Run(string[] arguments)
|
||||
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments)
|
||||
{
|
||||
if (arguments != null)
|
||||
{
|
||||
if (commandEngine.ContainsCommand(arguments[0]))
|
||||
{
|
||||
if (arguments.Length < 2) ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(null));
|
||||
if (arguments.Length < 2) userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(null));
|
||||
for (int i = 1; i < arguments.Length; i++)
|
||||
{
|
||||
ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(arguments[i]));
|
||||
userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(arguments[i]));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -32,20 +32,21 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleUtilities.WriteWrappedLine("Tools for RecrownedGTK library. Possible commands are as follows:\n");
|
||||
userOutput.WrappedOutput("Tools for RecrownedGTK library. Possible commands are as follows:\n");
|
||||
foreach (EngineCommand engineCommand in commandEngine.commands)
|
||||
{
|
||||
for (int i = 0; i < engineCommand.InvokeStrings.Length; i++)
|
||||
{
|
||||
ConsoleUtilities.WriteWrapped(engineCommand.InvokeStrings[i]);
|
||||
userOutput.WrappedOutput(engineCommand.InvokeStrings[i]);
|
||||
if (i + 1 < engineCommand.InvokeStrings.Length)
|
||||
{
|
||||
ConsoleUtilities.WriteWrapped(", ");
|
||||
userOutput.WrappedOutput(", ");
|
||||
}
|
||||
}
|
||||
ConsoleUtilities.WriteWrapped(" : ");
|
||||
ConsoleUtilities.WriteWrapped(engineCommand.Help().Replace("\n", "\n\t"), true);
|
||||
Console.WriteLine("--------");
|
||||
userOutput.WrappedOutput(" : ");
|
||||
userOutput.WrappedOutput(engineCommand.Help().Replace("\n", "\n\t"));
|
||||
userOutput.WrappedOutput("\n");
|
||||
userOutput.Output("--------");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@
|
||||
help = "Exits the tool.";
|
||||
}
|
||||
|
||||
public override void Run(string[] arguments = null)
|
||||
public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null)
|
||||
{
|
||||
commandEngine.running = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user