protected void FireTerminalCommandExecuting(ITerminalCommand terminalCommand, string prompt) { if (TerminalCommandExecuting != null) { TerminalCommandExecuting.Invoke(this, terminalCommand, prompt); } }
protected void FireTerminalCommandDidExecuted(ITerminalCommand terminalCommand) { if (TerminalCommandDidExecuted != null) { TerminalCommandDidExecuted.Invoke(this, terminalCommand); } }
internal void Execute(string line) { string[] split = line.Split(' '); string cmd = split[0]; string[] args = new string[split.Length - 1]; for (int i = 1; i < split.Length; i++) { args[i - 1] = split[i]; } ITerminalCommand command = _commands[cmd]; command.Execute(args); }
internal void LoadCommand(ITerminalCommand command) { if (command == null) { return; } Logger.Log($"Found: {command.Name} (from {command.GetType().FullName})"); //Avoid commands with the same name! if (_localCommands.FirstOrDefault(x => x.Name == command.Name) != null) { Logger.Log($"COMMAND CONFLICT: Two commands with the same name: {command.Name} (from {command.GetType().FullName}) and {_localCommands.FirstOrDefault(y => y.Name == command.Name).Name} (from {_localCommands.FirstOrDefault(y => y.Name == command.Name).GetType().FullName}). Skipping.", System.ConsoleColor.DarkYellow); throw new ArgumentException("A command with the same name already exists in the database."); } _localCommands.Add(command); Logger.Log("Injecting dependencies for the command..."); _plexgate.Inject(command); Logger.Log("Done."); Logger.Log("Creating usage string..."); StringBuilder sb = new StringBuilder(); sb.AppendLine($"{command.Name}"); sb.AppendLine(); sb.AppendLine("Summary:"); sb.AppendLine($" {command.Description}"); sb.AppendLine(); sb.AppendLine("Usage:"); //This is the tough part. if (command.Usages == null || command.Usages.Count() == 0) { //No arguments for the command, just add the command name as a usage string so Docopt doesn't get confused. sb.AppendLine($" {command.Name}"); } else { foreach (var usage in command.Usages) { sb.AppendLine($" {command.Name} {usage}"); } } //Add usage string to the database. _usages.Add(command.Name, sb.ToString()); Logger.Log("Done."); }
public void Consume(ITerminalCommand terminalCommand) { terminalCommand.Execute(this, (text) => { FireTerminalCommandExecuting(terminalCommand, text); }); if (terminalCommand.Handled) { FireTerminalCommandDidExecuted(terminalCommand); return; } foreach (var innerTerminalCommandChannel in InnerTerminalCommandChannels) { innerTerminalCommandChannel.Consume(terminalCommand); if (terminalCommand.Handled) { return; } } }
private void OnTerminalCommandDidExecuted(ITerminalCommandChannel terminalCommandChannel, ITerminalCommand terminalCommand) { FireTerminalCommandDidExecuted(terminalCommand); }
private void OnTerminalCommandExecuting(ITerminalCommandChannel terminalCommandChannel, ITerminalCommand terminalCommand, string prompt) { FireTerminalCommandExecuting(terminalCommand, prompt); }
public void AddCommand(string name, ITerminalCommand command) { // TODO }
static void OnTerminalCommandDidExecuted(ITerminalCommandChannel terminalCommandChannel, ITerminalCommand terminalCommand) { if (terminalCommand.Result is BookmarkPage || terminalCommand.Result is BookmarkItem || terminalCommand.Result is BookmarkItem[]) { if (terminalCommand.Result == null) { return; } if (terminalCommand.Result is BookmarkPage) { foreach (var bookmarkItem in (terminalCommand.Result as BookmarkPage).RootItems) { Console.WriteLine(DumpBookmarkItem(bookmarkItem, 0, false)); } } else if (terminalCommand.Result is BookmarkItem) { Console.WriteLine(DumpBookmarkItem(terminalCommand.Result as BookmarkItem, 0, false)); } else if (terminalCommand.Result is BookmarkItem[]) { foreach (var bookmarkItem in (terminalCommand.Result as BookmarkItem[])) { Console.WriteLine(DumpBookmarkItem(bookmarkItem, 0, false)); } } } else { Console.WriteLine(terminalCommand.Result); } }
static void OnTerminalCommandExecuting(ITerminalCommandChannel terminalCommandChannel, ITerminalCommand terminalCommand, string prompt) { Console.WriteLine(prompt); }
private void OnTerminalCommandDidExecuted(ITerminalCommandChannel terminalCommandChannel, ITerminalCommand terminalCommand) { if (terminalCommand.Result == null) { Console.WriteLine("Command [{0}] cannot be hit.", terminalCommand.TerminalCommandLine.CommandCode); } else { Console.WriteLine(terminalCommand.Result.ToString()); } }