diff --git a/Commander.NET/Command.cs b/Commander.NET/Command.cs index 1a31187..3afefd3 100644 --- a/Commander.NET/Command.cs +++ b/Commander.NET/Command.cs @@ -21,7 +21,7 @@ public class Command { Identifiers = Array.Empty(); HelpText = string.Empty; - Method = new Func((_) => CommandResult.Success); + Method = new Func((_) => CommandResult.Success()); } public Command Register(Action method, params string[] identifiers) diff --git a/Commander.NET/CommandResult.cs b/Commander.NET/CommandResult.cs index d8f4393..a6fa843 100644 --- a/Commander.NET/CommandResult.cs +++ b/Commander.NET/CommandResult.cs @@ -5,13 +5,24 @@ public class CommandResult public ResultType ResultType { get; } public string Message { get; } - public static CommandResult Success => new CommandResult(ResultType.Success); - public static CommandResult InvalidInput => new CommandResult(ResultType.InvalidInput); - public static CommandResult InternalError => new CommandResult(ResultType.InternalError); - public CommandResult(ResultType type, string message = "") { ResultType = type; Message = message; } + + public static CommandResult Success(string message = "") + { + return new CommandResult(ResultType.Success, message); + } + + public static CommandResult InvalidInput(string message = "") + { + return new CommandResult(ResultType.InvalidInput, message); + } + + public static CommandResult Error(string message = "") + { + return new CommandResult(ResultType.Error, message); + } } \ No newline at end of file diff --git a/Commander.NET/CommandResults.cs b/Commander.NET/CommandResults.cs index ef3b3a7..4ad33fb 100644 --- a/Commander.NET/CommandResults.cs +++ b/Commander.NET/CommandResults.cs @@ -4,6 +4,6 @@ public enum ResultType { Success, InvalidInput, - InternalError, + Error, UnexpectedError } \ No newline at end of file diff --git a/Commander.Test/Program.cs b/Commander.Test/Program.cs index a951448..7000a67 100644 --- a/Commander.Test/Program.cs +++ b/Commander.Test/Program.cs @@ -9,14 +9,13 @@ sayCommand.Register(HahaYesSub, "kek"); commander.Register(HahaNo, "scream", "yell"); commander.Register(Add, "add"); commander.Register((args) => Console.Clear(), "clear"); -commander.Register((input) => commander.PrintHelp(input) ? CommandResult.Success : CommandResult.InvalidInput, "help"); +commander.Register((input) => commander.PrintHelp(input) ? CommandResult.Success() : CommandResult.InvalidInput(), "help"); -Command fancyCommand = commander.Register(_ => new CommandResult(ResultType.InvalidInput, "How about no?"), "fancy"); +Command fancyCommand = commander.Register(_ => CommandResult.InvalidInput("Nonono"), "fancy"); fancyCommand.Register(new Command() { Identifiers = new string[] { "yes", "YES" }, HelpText = "Says that the input is fancy", - Method = (i) => { Console.WriteLine($"Yes, {i} is very fancy!"); return new CommandResult(ResultType.Success); } }); @@ -37,7 +36,7 @@ while (true) { ResultType.Success => ConsoleColor.Green, ResultType.InvalidInput => ConsoleColor.DarkYellow, - ResultType.InternalError => ConsoleColor.Red, + ResultType.Error => ConsoleColor.Red, ResultType.UnexpectedError => ConsoleColor.DarkRed, _ => ConsoleColor.Magenta }; @@ -53,7 +52,6 @@ while (true) Console.ResetColor(); _ = commander.PrintHelp(); - } Console.WriteLine(); } @@ -88,5 +86,5 @@ CommandResult Add(string input) return new CommandResult(ResultType.InvalidInput, "Invalid input!"); } Console.WriteLine(int.Parse(parts[0]) + int.Parse(parts[1])); - return CommandResult.Success; + return CommandResult.Success(); } \ No newline at end of file