recrownedgtk/RecrownedGTK.Tools/ConsoleInterface/ConsoleProgram.cs

69 lines
2.5 KiB
C#

using RecrownedGTK.Tools.CommandProcessor;
using RecrownedGTK.Tools.CommandProcessor.Commands;
using RecrownedGTK.Tools.NinePatchTools;
using RecrownedGTK.Tools.TextureAtlasTools;
using System;
using System.Reflection;
using System.Text;
namespace RecrownedGTK.Tools.ConsoleInterface
{
internal class ConsoleProgram
{
private class ConsoleInput : IUserInput {
public string GetInput() {
return Console.ReadLine();
}
}
private class ConsoleOutput : IUserOutput {
public void Output(string output) {
Console.WriteLine(output);
}
public void WrappedOutput(string output) {
ConsoleUtilities.WrapMessageToConsoleWidth(output);
}
public void ClearOutput() {
Console.Clear();
}
}
static void Main(string[] args)
{
ConsoleInput consoleInput = new ConsoleInput();
ConsoleOutput consoleOutput = new ConsoleOutput();
CommandEngine ce = new CommandEngine();
ConsoleUtilities.WrapMessageToConsoleWidth("Recrowned Athenaeum Console Tools version " + Assembly.GetExecutingAssembly().GetName().Version.ToString());
ConsoleUtilities.WrapMessageToConsoleWidth("Type \"help\" for help.");
ce.commands.Add(new HelpCommand(ce));
ce.commands.Add(new TexturePackerCommand());
ce.commands.Add(new StopCommand(ce));
ce.commands.Add(new ClearConsoleCommand());
ce.commands.Add(new NinePatchCommand());
if (args.Length > 0)
{
ConsoleUtilities.WrapMessageToConsoleWidth("Executing as one time use.");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.Length; i++) sb.Append(args[i] + ' ');
string commandAndArgs = sb.ToString().TrimEnd();
try
{
ConsoleUtilities.WrapMessageToConsoleWidth("Command and argument received: " + commandAndArgs);
ce.Process(consoleInput, consoleOutput, commandAndArgs);
}
catch (ArgumentException e)
{
ConsoleUtilities.WrapMessageToConsoleWidth("An error has occurred: " + e.Message);
}
}
else
{
ce.Run(consoleInput, consoleOutput);
}
}
}
}