Recursive InternalActionOption list
This commit is contained in:
@@ -9,6 +9,7 @@ using DiscordBotCore.Interfaces;
|
|||||||
using DiscordBotCore.Others;
|
using DiscordBotCore.Others;
|
||||||
using DiscordBotCore.Others.Actions;
|
using DiscordBotCore.Others.Actions;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
using Spectre.Console.Rendering;
|
||||||
|
|
||||||
namespace DiscordBot.Bot.Actions;
|
namespace DiscordBot.Bot.Actions;
|
||||||
|
|
||||||
@@ -27,9 +28,12 @@ public class Help: ICommandAction
|
|||||||
public async Task Execute(string[] args)
|
public async Task Execute(string[] args)
|
||||||
{
|
{
|
||||||
TableData tableData = new TableData();
|
TableData tableData = new TableData();
|
||||||
|
|
||||||
if (args == null || args.Length == 0)
|
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"];
|
tableData.Columns = ["Command", "Usage", "Description", "Options"];
|
||||||
|
|
||||||
foreach (var a in Application.CurrentApplication.InternalActionManager.Actions)
|
foreach (var a in Application.CurrentApplication.InternalActionManager.Actions)
|
||||||
@@ -40,25 +44,13 @@ public class Help: ICommandAction
|
|||||||
|
|
||||||
if (a.Value.ListOfOptions.Any())
|
if (a.Value.ListOfOptions.Any())
|
||||||
{
|
{
|
||||||
|
tableData.AddRow([actionName, usage, description, CreateTableWithSubOptions(a.Value.ListOfOptions)]);
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tableData.AddRow([actionName, usage, description]);
|
tableData.AddRow([actionName, usage, description]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// render the table
|
// render the table
|
||||||
@@ -83,4 +75,28 @@ public class Help: ICommandAction
|
|||||||
|
|
||||||
tableData.PrintTable();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,15 @@ public class Plugin: ICommandAction
|
|||||||
new InternalActionOption("help", "Displays this message"),
|
new InternalActionOption("help", "Displays this message"),
|
||||||
new InternalActionOption("list", "Lists all plugins"),
|
new InternalActionOption("list", "Lists all plugins"),
|
||||||
new InternalActionOption("load", "Loads 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("refresh", "Refreshes the plugin list"),
|
||||||
new InternalActionOption("uninstall", "Uninstalls a plugin"),
|
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;
|
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||||
|
|||||||
@@ -36,6 +36,24 @@ namespace DiscordBot.Utilities
|
|||||||
Rows.Add(row);
|
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()
|
public void PrintTable()
|
||||||
{
|
{
|
||||||
var table = new Table();
|
var table = new Table();
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
namespace DiscordBotCore.Others.Actions
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace DiscordBotCore.Others.Actions
|
||||||
{
|
{
|
||||||
public class InternalActionOption
|
public class InternalActionOption
|
||||||
{
|
{
|
||||||
public string OptionName { get; set; }
|
public string OptionName { get; set; }
|
||||||
public string OptionDescription { get; set; }
|
public string OptionDescription { get; set; }
|
||||||
|
|
||||||
|
public List<InternalActionOption> SubOptions { get; set; }
|
||||||
|
|
||||||
|
public InternalActionOption(string optionName, string optionDescription, List<InternalActionOption> subOptions)
|
||||||
|
{
|
||||||
|
OptionName = optionName;
|
||||||
|
OptionDescription = optionDescription;
|
||||||
|
SubOptions = subOptions;
|
||||||
|
}
|
||||||
|
|
||||||
public InternalActionOption(string optionName, string optionDescription)
|
public InternalActionOption(string optionName, string optionDescription)
|
||||||
{
|
{
|
||||||
OptionName = optionName;
|
OptionName = optionName;
|
||||||
OptionDescription = optionDescription;
|
OptionDescription = optionDescription;
|
||||||
|
SubOptions = new List<InternalActionOption>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user