This is a library with some application helpers.
The AppRunner allows you to run specific apps created by yourself. An app is just a class with the Application Attribute. In your app you can create commands with, optionally, flags and options. A flag is just an argument and a option is almost the same but they can contain a value. (For example.: Flag: "hello_this_is_a_flag", Option: "yourname=paul")
Just I said, an is a class with an Application Attribute.
[Application(Name = "TestApplication")] // <--- The Attribute
public class MyApplication
{
// ...
}
A command is a method with a CommandAttrbute. If you not set the name, it will be automaticly take the name from the method.
[Command(Name = "testcommand")]
public void Test()
{
// ...
}
It can be helpful if you add a description to your command. For example, you're creating a console application with some off these apps. It might be useful that the user can see what the command is doing.
[Command(Name = "testcommand", Description = "This command does nothing.")]
public void Test()
{
// ...
}
If you want to only execute the app and not a command you can create a "default command". Just set the Type to CommandType.DefaultCommand.
[Command(Type = CommandType.DefaultCommand)]
public void ThisIsDefault()
{
// ...
}
Just I said, you can add flags and options to your command. Just add a string List and a string Dictionary to your method parameters.
[Command(Name = "testcommand", Description = "This command does nothing.")]
public void Test(List<string> flags, Dictionary<string, string> options)
{
// ...
}
If you only want to get all arguments, then just add a string array.
[Command(Name = "testcommand", Description = "This command does nothing.")]
public void Test(string[] args)
{
// ...
}
Now we have our application with some commands. We only need to run it. Do that:
// 1.
AppRunner.Run<MyApplication>("testcommand", new string[] {"hello", "world=true"});
// 2.
AppRunner.Run(typeof(MyApplication), "testcommand", new string[] {"hello", "world=true"});
// Default Command
AppRunner.Run<MyApplication>(null, new string[] {"hello", "world=true"});
// No Arguments
AppRunner.Run<MyApplication>("testcommand", Array.Empty<string>());