diff --git a/DiscordBot/Bot/Actions/Help.cs b/DiscordBot/Bot/Actions/Help.cs index 7af945f..e9a30ce 100644 --- a/DiscordBot/Bot/Actions/Help.cs +++ b/DiscordBot/Bot/Actions/Help.cs @@ -9,6 +9,7 @@ using DiscordBotCore.Interfaces; using DiscordBotCore.Others; using DiscordBotCore.Others.Actions; using Spectre.Console; +using Spectre.Console.Rendering; namespace DiscordBot.Bot.Actions; @@ -27,9 +28,12 @@ public class Help: ICommandAction public async Task Execute(string[] args) { TableData tableData = new TableData(); + if (args == null || args.Length == 0) { + AnsiConsole.MarkupLine("[bold][green]Please make this window full screen to check all the commands.[/][/]"); + tableData.Columns = ["Command", "Usage", "Description", "Options"]; foreach (var a in Application.CurrentApplication.InternalActionManager.Actions) @@ -40,25 +44,13 @@ public class Help: ICommandAction if (a.Value.ListOfOptions.Any()) { - - var optionsTable = new Table(); - optionsTable.AddColumn("Option"); - optionsTable.AddColumn("Description"); - - foreach (var option in a.Value.ListOfOptions) - { - - optionsTable.AddRow(option.OptionName, option.OptionDescription); - } - - tableData.AddRow([actionName, usage, description, optionsTable]); + tableData.AddRow([actionName, usage, description, CreateTableWithSubOptions(a.Value.ListOfOptions)]); } else { tableData.AddRow([actionName, usage, description]); } - } // render the table @@ -83,4 +75,28 @@ public class Help: ICommandAction tableData.PrintTable(); } + + private Table CreateTableWithSubOptions(IEnumerable options) + { + var tableData = new TableData(); + tableData.Columns = ["Option", "Description", "SubOptions"]; + + foreach (var option in options) + { + + Markup optionName = new Markup($"{option.OptionName}"); + Markup description = new Markup($"{option.OptionDescription}"); + + if(option.SubOptions.Any()) + { + tableData.AddRow([optionName, description, CreateTableWithSubOptions(option.SubOptions)]); + + }else { + tableData.AddRow([optionName, description]); + } + + } + + return tableData.AsTable(); + } } diff --git a/DiscordBot/Bot/Actions/Plugin.cs b/DiscordBot/Bot/Actions/Plugin.cs index 6512fbe..d1651fc 100644 --- a/DiscordBot/Bot/Actions/Plugin.cs +++ b/DiscordBot/Bot/Actions/Plugin.cs @@ -21,10 +21,15 @@ public class Plugin: ICommandAction new InternalActionOption("help", "Displays this message"), new InternalActionOption("list", "Lists all plugins"), new InternalActionOption("load", "Loads all plugins"), - new InternalActionOption("install", "Installs a plugin"), + new InternalActionOption("install", "Installs a plugin", [ + new InternalActionOption("name", "The name of the plugin to install") + ]), new InternalActionOption("refresh", "Refreshes the plugin list"), new InternalActionOption("uninstall", "Uninstalls a plugin"), - new InternalActionOption("branch", "Sets a plugin option") + new InternalActionOption("branch", "Sets a plugin option", [ + new InternalActionOption("set", "Sets the branch"), + new InternalActionOption("get", "Gets the branch") + ]) }; public InternalActionRunType RunType => InternalActionRunType.ON_CALL; diff --git a/DiscordBot/Utilities/TableData.cs b/DiscordBot/Utilities/TableData.cs index 7006f72..01bdf8a 100644 --- a/DiscordBot/Utilities/TableData.cs +++ b/DiscordBot/Utilities/TableData.cs @@ -36,6 +36,24 @@ namespace DiscordBot.Utilities Rows.Add(row); } + public Table AsTable() + { + + var table = new Table(); + table.Border(this.HasRoundBorders ? TableBorder.Rounded : TableBorder.Square); + table.AddColumns(this.Columns.ToArray()); + table.ShowRowSeparators = DisplayLinesBetweenRows; + foreach (var row in this.Rows) + { + table.AddRow(row.Select(element => element.Match( + (data) => new Markup(data), + (data) => data + ))); + } + + return table; + } + public void PrintTable() { var table = new Table(); diff --git a/DiscordBotCore/Others/Actions/InternalActionOption.cs b/DiscordBotCore/Others/Actions/InternalActionOption.cs index 88c451b..0b2b338 100644 --- a/DiscordBotCore/Others/Actions/InternalActionOption.cs +++ b/DiscordBotCore/Others/Actions/InternalActionOption.cs @@ -1,14 +1,26 @@ -namespace DiscordBotCore.Others.Actions +using System.Collections.Generic; + +namespace DiscordBotCore.Others.Actions { public class InternalActionOption { public string OptionName { get; set; } public string OptionDescription { get; set; } + public List SubOptions { get; set; } + + public InternalActionOption(string optionName, string optionDescription, List subOptions) + { + OptionName = optionName; + OptionDescription = optionDescription; + SubOptions = subOptions; + } + public InternalActionOption(string optionName, string optionDescription) { OptionName = optionName; OptionDescription = optionDescription; + SubOptions = new List(); } } }