Skip to content

Commit 3c383f6

Browse files
committed
Added customcommands command to list non-built-in commands.
1 parent 12023eb commit 3c383f6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Runtime/Command.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ private Command() { }
186186
/// </summary>
187187
internal Action DefaultCallback { get; private set; }
188188

189+
/// <summary>
190+
/// Whether the command is a custom command.
191+
/// </summary>
192+
internal bool IsCustomCommand { get; private set; }
193+
189194
#endregion
190195

191196
#region Methods
@@ -229,6 +234,14 @@ internal bool HasAlias(params string[] aliases)
229234
return aliases.Length > 0 && aliases.Any(a => !string.IsNullOrEmpty(a) && Aliases.Contains(a.ToLower()));
230235
}
231236

237+
/// <summary>
238+
/// Set whether the command is a custom command.
239+
/// </summary>
240+
internal void SetAsCustomCommand()
241+
{
242+
IsCustomCommand = true;
243+
}
244+
232245
/// <summary>
233246
/// Get the command name as a formatted string.
234247
/// </summary>

Runtime/DevConsoleMono.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ internal bool AddCommand(Command command, bool onlyInDevBuild = false)
420420
if (!string.IsNullOrEmpty(command.Name) && !_commands.ContainsKey(command.Name) && !_commands.Values.Select(c => c.Aliases).Any(a => command.HasAlias(a)))
421421
{
422422
_commands.Add(command.Name, command);
423+
424+
if (!_init)
425+
{
426+
command.SetAsCustomCommand();
427+
}
428+
423429
return true;
424430
}
425431
return false;
@@ -1042,6 +1048,26 @@ private void InitBuiltInCommands()
10421048
}
10431049
));
10441050

1051+
AddCommand(Command.Create(
1052+
"customcommands",
1053+
"",
1054+
"Display a sorted list of all available custom commands",
1055+
() =>
1056+
{
1057+
IList<string> customCommands = _commands.Keys.Where(s => _commands[s].IsCustomCommand).ToList();
1058+
1059+
if (customCommands?.Count == 0)
1060+
{
1061+
Log("There are no custom commands defined.");
1062+
return;
1063+
}
1064+
1065+
LogSeperator("Custom commands");
1066+
Log(string.Join(", ", customCommands.OrderBy(s => s)));
1067+
LogSeperator();
1068+
}
1069+
));
1070+
10451071
AddCommand(Command.Create(
10461072
"consoleversion",
10471073
"",

0 commit comments

Comments
 (0)