internal Object GetArgumentValue(ICommandInterpreter interpreter, ArgumentList args, string[] allArguments) { object value = null; if (IsInterpreter) return interpreter; if (IsAllArguments) { args.Clear(); args.Unnamed.Clear(); return allArguments; } foreach (string name in AllNames) { ArgumentList.Item argitem; if (args.TryGetValue(name, out argitem)) { if (Parameter.ParameterType == typeof(string[])) value = argitem.Values; else if (IsFlag) { bool result; value = (String.IsNullOrEmpty(argitem.Value) || (bool.TryParse(argitem.Value, out result) && result)); } else value = argitem.Value; args.Remove(name); } } return base.ChangeType(value, Parameter.ParameterType, Required, DefaultValue); }
public void HtmlHelp(ICommandInterpreter _ci) { CommandInterpreter ci = ((CommandInterpreter)_ci); HtmlLightDocument doc = new HtmlLightDocument(ci.GetHtmlHelp("help")); XmlLightElement e = doc.SelectRequiredNode("/html/body/h1[2]"); XmlLightElement body = e.Parent; int i = body.Children.IndexOf(e); body.Children.RemoveRange(i, body.Children.Count - i); StringWriter sw = new StringWriter(); // Command index sw.WriteLine("<html><body>"); sw.WriteLine("<h1>All Commands:</h1>"); sw.WriteLine("<blockquote><ul>"); ILookup<string, ICommand> categories = ci.Commands.Where(c => c.Visible).ToLookup(c => c.Category ?? "Unk"); foreach (IGrouping<string, ICommand> group in categories.OrderBy(g => g.Key)) { sw.WriteLine("<li><a href=\"#{0}\">{0}</a></li>", group.Key); sw.WriteLine("<ul>"); foreach (ICommand cmd in group) sw.WriteLine("<li><a href=\"#{0}\">{0}</a> - {1}</li>", cmd.DisplayName, HttpUtility.HtmlEncode(cmd.Description)); sw.WriteLine("</ul>"); } sw.WriteLine("</ul></blockquote>"); // Command Help foreach (IGrouping<string, ICommand> group in categories.OrderBy(g => g.Key)) { sw.WriteLine("<h2><a name=\"{0}\"></a>{0} Commands:</h2>", group.Key); sw.WriteLine("<blockquote>"); foreach (ICommand cmd in group) { e = new HtmlLightDocument(ci.GetHtmlHelp(cmd.DisplayName)).SelectRequiredNode("/html/body/h3"); sw.WriteLine("<a name=\"{0}\"></a>", cmd.DisplayName); sw.WriteLine(e.InnerXml); sw.WriteLine(e.NextSibling.NextSibling.InnerXml); } sw.WriteLine("</blockquote>"); } e = new HtmlLightDocument(sw.ToString()).SelectRequiredNode("/html/body"); body.Children.AddRange(e.Children); string html = body.Parent.InnerXml; string path = Path.Combine(Path.GetTempPath(), "HttpClone.Help.html"); File.WriteAllText(path, html); System.Diagnostics.Process.Start(path); }
public virtual void Run(ICommandInterpreter interpreter, string[] arguments) { ArgumentList args = new ArgumentList(arguments); if (args.Count == 1 && args.Contains("?")) { Help(); return; } //translate ordinal referenced names Argument last = null; for (int i = 0; i < _arguments.Length && args.Unnamed.Count > 0; i++) { if (_arguments[i].Type == typeof (ICommandInterpreter)) break; last = _arguments[i]; args.Add(last.DisplayName, args.Unnamed[0]); args.Unnamed.RemoveAt(0); } if (last != null && args.Unnamed.Count > 0 && last.Type.IsArray) { for (int i = 0; i < _arguments.Length && args.Unnamed.Count > 0; i++) { args.Add(last.DisplayName, args.Unnamed[0]); args.Unnamed.RemoveAt(0); } } List<object> invokeArgs = new List<object>(); foreach (Argument arg in _arguments) { object argValue = arg.GetArgumentValue(interpreter, args, arguments); invokeArgs.Add(argValue); } //make sure we actually used all arguments. List<string> names = new List<string>(args.Keys); InterpreterException.Assert(names.Count == 0, "Unknown argument(s): {0}", String.Join(", ", names.ToArray())); InterpreterException.Assert(args.Unnamed.Count == 0, "Too many arguments supplied."); Invoke(Method, Target, invokeArgs.ToArray()); }
public void LoadInterpreter(ICommandInterpreter interpreter) { interpreter.StartInterpreter(instance); lock (InterpretersLoaded) InterpretersLoaded.Add(interpreter); }
public CommandProcessorRobotWorldLines(ICommandInterpreter commandInterpreter, World world, IPersist<WorldEdgeLine> store) : base(commandInterpreter, world) { _store = store; }
public FilterChainItem(ICommandInterpreter ci, ICommandFilter filter, ICommandChain next) { _ci = Check.NotNull(ci); _filter = Check.NotNull(filter); _next = Check.NotNull(next); }
public override void Run(ICommandInterpreter interpreter, string[] arguments) { Run(interpreter, null, arguments); }
public void Run(ICommandInterpreter ci, ICommandChain chain, string[] arguments) { _filterProc(ci, chain, arguments); }
public static void Build( ICommandInterpreter ci, [Argument("projects", Description = "One or more projects or directories to scan for projects")] [AllArguments] string[] projectFiles) { string value; CmdToolBuilder builder = new CmdToolBuilder(); Visitor(ArgumentList.Remove(ref projectFiles, "fast", out value), projectFiles, builder.Generate); }
public static void HelpFilter(ICommandInterpreter ci, ICommandChain chain, string[] args) { if (args.Length == 1 && StringComparer.OrdinalIgnoreCase.Equals("help", args[0]) || args[0] == "?") { chain.Next(args); Console.WriteLine(@"Global Options: /nologo: Suppress the logo/copyright message /verbosity: [All] Verbosity level: Off, Error, Warning, Information, Verbose, or All "); } else { chain.Next(args); } }
public static void ExceptionFilter(ICommandInterpreter ci, ICommandChain chain, string[] args) { try { chain.Next(args); } catch (System.Threading.ThreadAbortException) { throw; } catch (CommandInterpreter.QuitException) { throw; } catch (OperationCanceledException) { throw; } catch (InterpreterException) { // Incorrect useage or bad command name... throw; } catch (Exception ex) { if (args.Length > 0) Trace.TraceError("[{0}]: {1}", args[0], ex); else Trace.TraceError("{0}", ex); throw; } }
public void Execute(ICommandInterpreter cmd) { m_delegate(cmd); }
/// <summary> /// Creates a new instance of the Command class. /// </summary> /// <param name="interpreter">The command interpreter to which this command should be issued to.</param> /// <param name="name">The unique name of this command.</param> public Command(ICommandInterpreter interpreter, string name) { this.interpreter = interpreter; this.name = name; }
public void Help( [Argument("name", "command", "c", "option", "o", Description = "The name of the command or option to show help for.", DefaultValue = null)] string name, ICommandInterpreter ci ) { ICommand cmd; if (name != null) { Dictionary<string, ICommand> cmds = new Dictionary<string, ICommand>(StringComparer.OrdinalIgnoreCase); foreach (ICommand c in ci.Commands) foreach (string nm in c.AllNames) cmds[nm] = c; if (cmds.TryGetValue(name, out cmd)) { cmd.Help(); return; } Console.WriteLine("Unknown command: {0}", name); Console.WriteLine(); Environment.ExitCode = 1; } int padding = 4 + ci.Commands.Max(c => c.DisplayName.Length); string format = "{0," + padding + "}: {1}"; ILookup<string, ICommand> categories = ci.Commands.Where(c=>c.Visible).ToLookup(c => c.Category ?? "Unk"); foreach (IGrouping<string, ICommand> group in categories.OrderBy(g => g.Key)) { Console.WriteLine("{0}:", group.Key); foreach (ICommand item in group) { Console.WriteLine(format, item.DisplayName, item.Description); } Console.WriteLine(); } }
public FilterChainItem(ICommandInterpreter ci, ICommandFilter filter, ICommandChain next) { _ci = ci; _filter = filter; _next = next; }
public Engine(ICommandInterpreter commandInterpreter) { this.commandInterpreter = commandInterpreter; }