private static void Help() { int totalCommandCount = CommandConsole.Current.CommandRegistry.AllRegisteredCommands.GetCommandCount(); if (totalCommandCount == 0) { LConsole.WriteLine("Uh oh, there aren't any registered commands"); return; } int maxUsageLength = GetMaxCommandUsageLength(CommandConsole.Current.CommandRegistry.AllRegisteredCommands.EnumerateAllCommands()); LineWriter writer = LConsole.BeginLine(); writer.WriteLine($"Available commands ({totalCommandCount}):", ConsoleColor.Magenta); writer.WriteLine(); foreach (string assemblyName in CommandConsole.Current.CommandRegistry.CommandsByAssembly.Keys.OrderBy(s => s)) { WriteAssemblyCommands(maxUsageLength, writer, assemblyName); writer.WriteLine(); } writer.End(); }
private static void HelpAss(string assemblyName) { if (!CommandConsole.Current.CommandRegistry.CommandsByAssembly.TryGetValue(assemblyName, out var commands)) { LConsole.WriteLine($"No assembly with commands found by name {assemblyName}. See `help` for commands in all assemblies."); return; } int maxUsageLength = GetMaxCommandUsageLength(commands); LineWriter writer = LConsole.BeginLine(); WriteAssemblyCommands(maxUsageLength, writer, assemblyName); writer.End(); }
private static void WriteAssemblyCommands(int maxUsageLength, LineWriter writer, string assemblyName) { var assemblyCommands = CommandConsole.Current.CommandRegistry.CommandsByAssembly[assemblyName]; string assemblyHeader = $"{assemblyName} ({assemblyCommands.Count} commands)"; writer.WriteLine(assemblyHeader, ConsoleColor.Yellow); foreach (var command in assemblyCommands.OrderBy(c => c.Name).ThenBy(c => c.RequiredParamCount).ThenBy(c => c.OptionalParamCount)) { if (command.Hidden) { continue; } int lineLength = 0; writer.Write(command.Name, ConsoleColor.Blue); lineLength += command.Name.Length; string paramsStr = " " + command.GetParamsString(); writer.Write(paramsStr, ConsoleColor.DarkGreen); lineLength += paramsStr.Length; if (command.Description != null) { if (lineLength < maxUsageLength) { writer.Write(new string('-', maxUsageLength - lineLength), ConsoleColor.DarkGray); } writer.Write(": ", ConsoleColor.DarkGray); writer.Write(command.Description, ConsoleColor.DarkYellow); } writer.WriteLine(); } }
/// <summary> /// Makes and returns a new line writer. This must be used if you want to write a line with different /// colored words. /// </summary> public static LineWriter BeginLine() => LineWriter.Start();