refactoring and added clear command.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Tools.CommandProcessor.Commands
|
||||
{
|
||||
internal class ClearConsoleCommand : EngineCommand
|
||||
{
|
||||
public ClearConsoleCommand() : base("clear")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string Help(string argument = null)
|
||||
{
|
||||
return "Clears the console.";
|
||||
}
|
||||
|
||||
public override void Run(string[] arguments = null)
|
||||
{
|
||||
Console.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Tools.CommandProcessor.Commands
|
||||
{
|
||||
internal class HelpCommand : EngineCommand
|
||||
{
|
||||
CommandEngine commandEngine;
|
||||
|
||||
public HelpCommand(CommandEngine commandEngine) : base("help")
|
||||
{
|
||||
this.commandEngine = commandEngine;
|
||||
}
|
||||
|
||||
public override string Help(string argument)
|
||||
{
|
||||
return "help [command] [arg]";
|
||||
}
|
||||
|
||||
|
||||
public override void Run(string[] arguments)
|
||||
{
|
||||
if (arguments != null)
|
||||
{
|
||||
if (commandEngine.ContainsCommand(arguments[0]))
|
||||
{
|
||||
if (arguments.Length < 2) ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(null));
|
||||
for (int i = 1; i < arguments.Length; i++)
|
||||
{
|
||||
ConsoleUtilities.WriteWrappedLine(commandEngine.GetCommand(arguments[0]).Help(arguments[i]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException(arguments[0] + " not a command. Type \"help\" for a list of commands.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleUtilities.WriteWrappedLine("Tools for RecrownedAthenaeum 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]);
|
||||
if (i + 1 < engineCommand.invokeStrings.Length)
|
||||
{
|
||||
ConsoleUtilities.WriteWrapped(", ");
|
||||
}
|
||||
}
|
||||
ConsoleUtilities.WriteWrapped(" : ");
|
||||
ConsoleUtilities.WriteWrapped(engineCommand.Help().Replace("\n", "\n\t"), true);
|
||||
Console.WriteLine("--------");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Tools.CommandProcessor.Commands
|
||||
{
|
||||
internal class StopCommand : EngineCommand
|
||||
{
|
||||
CommandEngine commandEngine;
|
||||
|
||||
public StopCommand(CommandEngine commandEngine) : base("quit", "stop", "q", "exit")
|
||||
{
|
||||
this.commandEngine = commandEngine;
|
||||
}
|
||||
|
||||
public override string Help(string argument = null)
|
||||
{
|
||||
return "Exits the tool.";
|
||||
}
|
||||
|
||||
public override void Run(string[] arguments = null)
|
||||
{
|
||||
commandEngine.running = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.Tools.CommandProcessor.Commands
|
||||
{
|
||||
class TestCommand : EngineCommand
|
||||
{
|
||||
public TestCommand() : base("test")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string Help(string argument = null)
|
||||
{
|
||||
switch (argument)
|
||||
{
|
||||
case null:
|
||||
return "Test command. Meant for testing random stuff. Current arguments: \"-textWrap\".\n" +
|
||||
"Its ironic that the help section is also meant to test things.";
|
||||
case "-textWrap":
|
||||
return "-textWrap prints a large amount of text to test the text wrap.";
|
||||
}
|
||||
return "Test command.";
|
||||
}
|
||||
|
||||
public override void Run(string[] arguments = null)
|
||||
{
|
||||
if (arguments != null && arguments[0] == "-textWrap")
|
||||
{
|
||||
ConsoleUtilities.WriteWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit.[here]\n Duis semper lacinia nisl, eget efficitur massa feugiat vel. Ut egestas elit id sollicitudin pellentesque.[here no space after break.]\nFusce ullamcorper nec turpis at aliquam. Donec cursus mi nec porttitor convallis. Nullam condimentum sollicitudin volutpat. Pellentesque tellus ligula, eleifend sit amet ante ac, accumsan volutpat lorem. Suspendisse potenti. Vestibulum at sodales ipsum. Mauris dignissim maximus purus sagittis elementum.", true);
|
||||
ConsoleUtilities.WriteWrapped("test");
|
||||
ConsoleUtilities.WriteWrapped(". ");
|
||||
ConsoleUtilities.WriteWrapped("test.");
|
||||
}
|
||||
base.Run(arguments);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user