mirror of
https://github.com/Stone-Red-Code/Commander.NET.git
synced 2026-09-04 00:46:08 +02:00
Code improvements
This commit is contained in:
@@ -7,6 +7,7 @@ Command sayCommand = commander.Register(HahaYes, "say", "yell");
|
||||
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");
|
||||
|
||||
@@ -28,14 +29,33 @@ fancyCommand.Register(new Command()
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (commander.ExecuteMultible(Console.ReadLine()!, out List<CommandResult> commandResult))
|
||||
if (commander.ExecuteMultible(Console.ReadLine()!, out List<CommandResult> commandResults))
|
||||
{
|
||||
commandResult.ForEach((e) => Console.WriteLine(e.ResultType + " " + e.Message));
|
||||
foreach (CommandResult commandResult in commandResults)
|
||||
{
|
||||
Console.ForegroundColor = commandResult.ResultType switch
|
||||
{
|
||||
ResultType.Success => ConsoleColor.Green,
|
||||
ResultType.InvalidInput => ConsoleColor.DarkYellow,
|
||||
ResultType.InternalError => ConsoleColor.Red,
|
||||
ResultType.UnexpectedError => ConsoleColor.DarkRed,
|
||||
_ => ConsoleColor.Magenta
|
||||
};
|
||||
|
||||
Console.WriteLine($"[{commandResult.ResultType}] {commandResult.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("xxx Command not found!");
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Command not found!");
|
||||
Console.ResetColor();
|
||||
|
||||
_ = commander.PrintHelp();
|
||||
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
void HahaYes(string yes)
|
||||
@@ -52,10 +72,21 @@ CommandResult HahaNo(string no)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(no))
|
||||
{
|
||||
return new CommandResult(ResultType.InvalidInput, "fuck off");
|
||||
return new CommandResult(ResultType.InvalidInput, "No the command doesn't work like that!");
|
||||
}
|
||||
|
||||
Console.WriteLine($">>> {no.ToUpper()}");
|
||||
|
||||
return new CommandResult(ResultType.Success);
|
||||
}
|
||||
|
||||
CommandResult Add(string input)
|
||||
{
|
||||
string[] parts = input.Split(' ');
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
return new CommandResult(ResultType.InvalidInput, "Invalid input!");
|
||||
}
|
||||
Console.WriteLine(int.Parse(parts[0]) + int.Parse(parts[1]));
|
||||
return CommandResult.Success;
|
||||
}
|
||||
Reference in New Issue
Block a user