public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { List<string> list = new List<string>(); for(int i = 0; i < alternatives.Length; i++) { string s = alternatives[i]; if (s.StartsWith(lastWord)) list.Add(s); } return list.GetEnumerator(); }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { // if we already have one arguemnt and try to expand the next: no. int argc = partialCommand.Split(' ').Length; if (argc > 2 || (argc == 2 && lastWord.Length == 0)) { return null; } IEnumerator<string> it = Application.Commands.GetRegisteredCommandNames(lastWord).GetEnumerator(); return new SortedMatchEnumerator(lastWord, it); }
protected ShellApplication() { output = new ConsoleOutputDevice(System.Console.Out, true); message = new ConsoleOutputDevice(System.Console.Error, false); input = new ConsoleInputDevice(); dispatcher = new CommandDispatcher(this); if (this is ISettingsHandler) settings = new ApplicationSettings(this); if (this is IPropertyHandler) properties = new PropertyRegistry(this as IPropertyHandler); if (this is IPluginHandler) plugins = new ApplicationPlugins(this); interruptHandler = new ApplicationInterruptionHandler(this); }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { IEnumerator<string> complete = null; SortedList<string, string> commands = new SortedList<string, string>(); commands.Add("analytics", ""); commands.Add("free", ""); commands.Add("network", ""); commands.Add("paths", ""); commands.Add("status", ""); string[] sp = partialCommand.Trim().Split(' '); if (sp.Length >= 1 && String.Compare(sp[0], "show", true) == 0) { if (lastWord.Length > 0) { complete = SubsetCollection<string>.Tail(commands, lastWord).GetEnumerator(); } else { complete = commands.Keys.GetEnumerator(); } } return complete; }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { string[] sp = partialCommand.Trim().Split(' '); IEnumerator<string> complete = null; if (sp.Length >= 1) { List<string> list = new List<string>(); string s = sp[sp.Length - 1].ToLower(); if (s == "connect") { list.Add("to"); } else if (s == "identified") { list.Add("by"); } else if (s == "to") { //TODO: load the saved addresses ... } else if (s == "on") { list.Add("http"); list.Add("tcp"); } else if (s == "with") { list.Add("xml"); list.Add("json"); list.Add("binary"); } else if (sp.Length == 3 && sp[1] == "to") { list.Add("with"); list.Add("on"); } else if (s == "http" || s == "tcp") { list.Add("with"); list.Add("identified"); } else if (s == "xml" || s == "json" || s == "binary") { list.Add("on"); list.Add("identified"); } complete = new Collections.SortedMatchEnumerator(lastWord, list, StringComparer.InvariantCultureIgnoreCase); } return complete; }
/// <summary> /// Returns a list of strings that are possible at this stage. /// </summary> /// <param name="dispatcher">The <see cref="CommandDispatcher"/> that /// can be used to access other values through it.</param> /// <param name="partialCommand">The command typed so far.</param> /// <param name="lastWord">The last word returned by readline.</param> /// <remarks> /// Used for the readline-completion in interactive mode. Based on /// the partial command and the <paramref name="lastWord"/> you have /// to determine the words that are available at this stage. Returns /// <b>null</b>, if you don't know a possible completion. /// </remarks> /// <returns> /// </returns> public virtual IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { return null; }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { return Application.Commands.Aliases.Complete(partialCommand, lastWord); }
internal CommandAliases(CommandDispatcher dispatcher) { aliases = new SortedDictionary <string, string>(); dispatcher = dispatcher; currentExecutedAliases = new List <string>(); }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { return base.Complete(dispatcher, partialCommand, lastWord); }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { PropertyRegistry properties = Properties; return properties == null ? null : properties.Complete(Name, partialCommand, lastWord); }
public override IEnumerator <string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { ISettingsHandler handler = Application as ISettingsHandler; return(handler == null ? null : handler.Settings.Complete(partialCommand, lastWord)); }
public override IEnumerator <string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { return(base.Complete(dispatcher, partialCommand, lastWord)); }
public EchoCommandProperty(ShellApplication app, CommandDispatcher dispatcher) : base(false) { this.app = app; this.dispatcher = dispatcher; handler = new CommandEventHandler(OnDispatcherExecuting); }
public override IEnumerator <string> Complete(CommandDispatcher disp, string partialCommand, string lastWord) { return(Application.Commands.Aliases.Complete(partialCommand, lastWord)); }
public override IEnumerator<string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { ISettingsHandler handler = Application as ISettingsHandler; return handler == null ? null : handler.Settings.Complete(partialCommand, lastWord); }
/// <summary> /// Returns a list of strings that are possible at this stage. /// </summary> /// <param name="dispatcher">The <see cref="CommandDispatcher"/> that /// can be used to access other values through it.</param> /// <param name="partialCommand">The command typed so far.</param> /// <param name="lastWord">The last word returned by readline.</param> /// <remarks> /// Used for the readline-completion in interactive mode. Based on /// the partial command and the <paramref name="lastWord"/> you have /// to determine the words that are available at this stage. Returns /// <b>null</b>, if you don't know a possible completion. /// </remarks> /// <returns> /// </returns> public virtual IEnumerator <string> Complete(CommandDispatcher dispatcher, string partialCommand, string lastWord) { return(null); }
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args) { if (args.Count > 1) { return(CommandResultCode.SyntaxError); } string commandName = null; if (args.MoveNext()) { commandName = args.Current; } // nothing given: provide generic help. Application.Error.WriteLine(); int maxPad = 0; if (commandName == null) { ICollection <Command> commands = Application.Commands.RegisteredCommands; // process the command groups first... Dictionary <string, List <CommandHelp> > groups = new Dictionary <string, List <CommandHelp> >(); foreach (Command command in commands) { string groupName = command.GroupName; if (groupName == null || groupName.Length == 0) { groupName = "commands"; } List <CommandHelp> list; if (!groups.TryGetValue(groupName, out list)) { list = new List <CommandHelp>(); groups[groupName] = list; } CommandHelp commandHelp = new CommandHelp(); StringBuilder cmdPrint = new StringBuilder(" "); string[] aliases = command.Aliases; cmdPrint.Append(command.Name); if (aliases != null && aliases.Length > 0) { cmdPrint.Append(" | "); for (int i = 0; i < aliases.Length; i++) { if (i != 0) { cmdPrint.Append(" | "); } cmdPrint.Append(aliases[i]); } } commandHelp.Name = cmdPrint.ToString(); string description = command.ShortDescription; if (description == null) { // no description ... try to get the groups description... } commandHelp.Description = description; maxPad = Math.Max(maxPad, cmdPrint.Length); list.Add(commandHelp); } foreach (KeyValuePair <string, List <CommandHelp> > entry in groups) { string groupName = entry.Key; Application.Error.Write(groupName); Application.Error.Write(":"); Application.Error.WriteLine(); List <CommandHelp> commandList = entry.Value; foreach (CommandHelp command in commandList) { Application.Error.Write(" "); Application.Error.Write(command.Name); if (command.Description != null) { for (int i = 0; i < maxPad - command.Name.Length; ++i) { Application.Error.Write(" "); } Application.Error.Write(" : "); Application.Error.Write(command.Description); } Application.Error.WriteLine(); } } } else { CommandDispatcher disp = Application.Commands; string cmdString = disp.CompleteCommandName(commandName); Command c = disp.GetCommand(cmdString); if (c == null) { Application.Error.WriteLine("Help: unknown command '" + cmdString + "'"); Application.Error.WriteLine(); return(CommandResultCode.ExecutionFailed); } WriteDescription(c); } Application.Error.WriteLine(); return(CommandResultCode.Success); }