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 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(); } }