mirror of
https://github.com/Stone-Red-Code/Commander.NET.git
synced 2026-09-04 00:46:08 +02:00
- Add Result Code and Help function
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user