- Add Result Code and Help function

This commit is contained in:
Stone_Red
2022-04-23 14:38:12 +02:00
parent 81dd31b9f3
commit aad3ad502c
8 changed files with 302 additions and 55 deletions
+1
View File
@@ -5,6 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
+32 -4
View File
@@ -3,17 +3,38 @@
Console.WriteLine("Hello, World!");
Commander commander = new Commander();
Command sayCommand = commander.Register(HahaYes, "say", "tell");
Command sayCommand = commander.Register(HahaYes, "say", "yell");
sayCommand.Register(HahaYesSub, "kek");
commander.Register(HahaNo, "scream", "yell");
commander.Register((args) => Console.Clear(), "clear");
commander.Register((input) => commander.PrintHelp(input) ? CommandResult.Success : CommandResult.InvalidInput, "help");
Command fancyCommand = commander.Register(_ => new CommandResult(ResultType.InvalidInput, "How about no?"), "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); }
});
fancyCommand.Register(new Command()
{
Identifiers = new string[] { "no", "NO" },
HelpText = "Says that the input is not fancy",
Method = (i) => { Console.WriteLine($"Yes, {i} is not very fancy!"); return new CommandResult(ResultType.Success); }
});
while (true)
{
if (!commander.Execute(Console.ReadLine()!))
if (commander.ExecuteMultible(Console.ReadLine()!, out List<CommandResult> commandResult))
{
Console.WriteLine("Command not found!");
commandResult.ForEach((e) => Console.WriteLine(e.ResultType + " " + e.Message));
}
else
{
Console.WriteLine("xxx Command not found!");
}
}
@@ -27,7 +48,14 @@ void HahaYesSub(string yes)
Console.WriteLine($">>> {yes} xD");
}
void HahaNo(string no)
CommandResult HahaNo(string no)
{
if (string.IsNullOrWhiteSpace(no))
{
return new CommandResult(ResultType.InvalidInput, "fuck off");
}
Console.WriteLine($">>> {no.ToUpper()}");
return new CommandResult(ResultType.Success);
}