From 22b25cd8a85a982fb4de157ea93d730eaef4def3 Mon Sep 17 00:00:00 2001 From: Chris Bell Date: Wed, 1 Jan 2025 22:25:35 -0600 Subject: [PATCH] Various QOL changes --- DeafultCogwheelConsole.cs | 7 ++++++- src/COGWHEEL.cs | 11 ++++++++--- src/CommandsManager.cs | 24 +++++++++++++++++++++++- src/interfaces/ICogwheelConsole.cs | 1 + 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/DeafultCogwheelConsole.cs b/DeafultCogwheelConsole.cs index 9d968b3..c65cf0f 100644 --- a/DeafultCogwheelConsole.cs +++ b/DeafultCogwheelConsole.cs @@ -16,7 +16,7 @@ public class DeafultCogwheelConsole : ICogwheelConsole CommandsManager = commandsManager; CommandsManager.RegisterObject(this); - Log(OpeningMessage); + Write(OpeningMessage); IsRunning = true; while (IsRunning) @@ -41,6 +41,11 @@ public class DeafultCogwheelConsole : ICogwheelConsole { Console.WriteLine($"[COGWHEEL WARNING] {message}"); } + + public void Write(string message) + { + Console.WriteLine(message); + } public void ClearConsole() { diff --git a/src/COGWHEEL.cs b/src/COGWHEEL.cs index 152bae2..6e705b8 100644 --- a/src/COGWHEEL.cs +++ b/src/COGWHEEL.cs @@ -43,6 +43,11 @@ public static class COGWHEEL _console.LogWarning(message); } + public static void Write(string message) + { + _console.Write(message); + } + // == Built-in commands == // [Command(Name = "quit", Description = "Quits the Cogwheel console.")] public static void QuitCogwheelConsole() @@ -76,7 +81,7 @@ public static class COGWHEEL { foreach (var command in _commandsManager.Commands) { - _console.Log($"{command.Key} - {command.Value.Description}"); + Write($"{_commandsManager.GetCommandUsage(command.Value)}"); } } @@ -86,7 +91,7 @@ public static class COGWHEEL _console.Log($"Current context: {_commandsManager.CurrentContext.GetType()} : {_commandsManager.CurrentContextGuid}"); } - [Command(Name = "test")] + [Command(Name = "test", Description = "Creates a new TestClass object.")] public static void CreateTestObject(string name) { _console.Log($"Creating new TestClass object with name: {name}"); @@ -110,7 +115,7 @@ public static class COGWHEEL Log("Available registered objects:"); foreach (var (guid, obj) in filteredObjects) { - Log($"- {obj.GetType().FullName} : {guid}"); + Write($"- {obj.GetType().FullName} : {guid}"); } } diff --git a/src/CommandsManager.cs b/src/CommandsManager.cs index 74be968..b75bef3 100644 --- a/src/CommandsManager.cs +++ b/src/CommandsManager.cs @@ -90,11 +90,33 @@ public class CommandsManager public virtual string GetCommandUsage(ICommand command) { + string output = ""; + if (!command.Method.IsStatic) + { + output += $"|{command.Method.DeclaringType?.FullName}| "; + } + else + { + output += "|Global| "; + } + + output += $"{command.Name}: "; + + if (!string.IsNullOrWhiteSpace(command.Description)) + { + output += $"{command.Description} "; + } + string paramUsage = string.Join(" ", command.Method.GetParameters().Select(param => $"<{(param.IsDefined(typeof(ParamArrayAttribute)) ? "params " : "")}{param}>")); + + if (!string.IsNullOrWhiteSpace(paramUsage)) + { + output += $"- {paramUsage}"; + } - return $"{command.Name}: {paramUsage}"; + return output; } public virtual bool ExecuteCommand(object obj, (ICommand command, List args) command) diff --git a/src/interfaces/ICogwheelConsole.cs b/src/interfaces/ICogwheelConsole.cs index 059d229..ee5fb6e 100644 --- a/src/interfaces/ICogwheelConsole.cs +++ b/src/interfaces/ICogwheelConsole.cs @@ -10,6 +10,7 @@ public interface ICogwheelConsole public void Log(string message); public void LogError(string message); public void LogWarning(string message); + public void Write(string message); public void ClearConsole(); public void Exit();