Recursive InternalActionOption list

This commit is contained in:
2024-06-06 16:07:31 +03:00
parent 23961a48b0
commit 1a5f0cbede
4 changed files with 67 additions and 16 deletions

View File

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

View File

@@ -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;