public static void register(ConsolerCommand cmd) { ConsolerMain.commands.Add(cmd); }
public static void listen() { Console.WriteLine("Erida Consoler v" + CR_VERSION + " for C#."); Console.WriteLine("Author - " + CR_AUTHOR); Console.WriteLine("Type \"help\" to get command list."); Console.Write("Consoler> "); ConsolerCommand helpCmd = new HelpCommand(commands) .setCommandName("help") .setShortHelpText("Write list of registred commands."); ConsolerCommand altHelpCmd = new HelpCommand(commands) .setCommandName("?") .setShortHelpText("Alternative command to write list of registred commands."); ConsolerCommand exitCmd = new ExitCommand() .setCommandName("exit") .setShortHelpText("Terminate all executed processes and close consoler."); ConsolerCommand versionCmd = new VersionCommand() .setCommandName("version") .setShortHelpText("Write version of consoler."); ConsolerCommand clearCmd = new ClearCommand() .setCommandName("clear") .setShortHelpText("Clear consoler space from text and other stuff."); ConsolerCommand sayCmd = new SayCommand() .setCommandName("say") .setShortHelpText("Print phrase with line break or without it.") .setFullHelpText("Print phrase with line break or without it.\n" + "Arguments:\n" + "-pl - Print line with line break.\n" + "-p - Print just text without line breaks."); ConsolerCommand scriptCmd = new ScriptCommand() .setCommandName("execute") .setShortHelpText("Execute script with consoler syntax.") .setFullHelpText("Execute script with consoler syntax. Lines must be ended by nothing, just line break to use next command.\n" + "Argument -p is the one, it's need to set path to executing file. File can be any extension and size."); register(helpCmd); register(altHelpCmd); register(exitCmd); register(versionCmd); register(clearCmd); register(sayCmd); register(scriptCmd); while (true) { string line = Console.ReadLine(); if (line != "") { ConsolerCommand dedicatedCommand = parseCommand(line); if (isCommandExists(dedicatedCommand.getCommandName())) { GetCommand(dedicatedCommand.getCommandName()).Merge(dedicatedCommand); GetCommand(dedicatedCommand.getCommandName()).executeCommand(); Console.Write("Consoler> "); } else { Console.WriteLine("Command \"" + dedicatedCommand.getCommandName() + "\" is not exist or not registred. Type \"help\" to " + "get registred commands list."); Console.Write("Consoler> "); } } else { Console.Write("Consoler> "); } } }
public void Merge(ConsolerCommand command) { this.CommandArgs = command.CommandArgs; this.CommandFlags = command.CommandFlags; }