/// <inheritdoc /> public override void Handle(string[] args) { InvariantDictionary <ICommand> commands = this.GetCommands(); // build output StringBuilder help = new(); if (!args.Any()) { help.AppendLine( $"The '{this.RootName}' command is the entry point for {this.ModName} commands. You use it by specifying a more " + $"specific command (like '{GenericHelpCommand.CommandName}' in '{this.RootName} {GenericHelpCommand.CommandName}'). Here are the available commands:\n\n" ); foreach (var entry in commands.OrderBy(p => p.Key, HumanSortComparer.DefaultIgnoreCase)) { help.AppendLine(entry.Value.Description); help.AppendLine(); help.AppendLine(); } } else if (commands.TryGetValue(args[0], out ICommand? command)) { help.AppendLine(command.Description); } else { help.AppendLine($"Unknown command '{this.RootName} {args[0]}'. Type '{this.RootName} {GenericHelpCommand.CommandName}' for available commands."); } // write output this.Monitor.Log(help.ToString().Trim(), LogLevel.Info); }
/********* ** Private methods *********/ /**** ** Commands ****/ /// <summary>Handle the 'patch help' command.</summary> /// <param name="args">The subcommand arguments.</param> /// <returns>Returns whether the command was handled.</returns> private bool HandleHelp(string[] args) { // generate command info var helpEntries = new InvariantDictionary <string> { ["help"] = $"{this.CommandName} help\n Usage: {this.CommandName} help\n Lists all available {this.CommandName} commands.\n\n Usage: {this.CommandName} help <cmd>\n Provides information for a specific {this.CommandName} command.\n - cmd: The {this.CommandName} command name.", ["summary"] = $"{this.CommandName} summary\n Usage: {this.CommandName} summary\n Shows a summary of the current conditions and loaded patches.", ["update"] = $"{this.CommandName} update\n Usage: {this.CommandName} update\n Imediately refreshes the condition context and rechecks all patches." }; // build output StringBuilder help = new StringBuilder(); if (!args.Any()) { help.AppendLine( $"The '{this.CommandName}' command is the entry point for Content Patcher commands. These are " + "intended for troubleshooting and aren't intended for players. You use it by specifying a more " + $"specific command (like 'help' in '{this.CommandName} help'). Here are the available commands:\n\n" ); foreach (var entry in helpEntries.OrderBy(p => p.Key)) { help.AppendLine(entry.Value); help.AppendLine(); } } else if (helpEntries.TryGetValue(args[0], out string entry)) { help.AppendLine(entry); } else { help.AppendLine($"Unknown command '{this.CommandName} {args[0]}'. Type '{this.CommandName} help' for available commands."); } // write output this.Monitor.Log(help.ToString()); return(true); }