Manual Command Resolution

AutoResolveCommands = false

Manual Command resolution means going low-level, not using the Commander's benefits.

Command auto-resolution is based on Command()] annotations and Command classes that inherit from CommandBase. Auto-resolution requires you to use the CLArgs Framework and it requires almost zero code.

Manual resolution requires a Commander instance first. There you can registers verbs-to-functions. When you then call commander.Execute()it will no longer resolve and look for a Command implementation, it will just search the registered functions.

private static void Main(string[] args)
{
    Commander commander = new Commander(new Settings
    {
        AutoResolveCommands = false
    });
    commander.RegisterFunction("word1", word);
    commander.RegisterFunction("word1.text2", text);
    commander.RegisterFunction("word1.text2.verb3", verb);
    
    CommandLineArguments commandLineArguments = CommandLineParser.Parse(args);
    commander.ExecuteCommand(commandLineArguments);
}

private static void word( CommandLineArguments commandLineArguments) 
    => Console.WriteLine("Function Word");
private static void text( CommandLineArguments commandLineArguments) 
    => Console.WriteLine("Function Text");
private static void verb( CommandLineArguments commandLineArguments) 
    => Console.WriteLine("Function Verb");

Please notice, there no Options-to-Parameters conversion. Instead, the registered function receives a CommandLineArguments object as input. A CommandLineArguments contains all provided Verbs, Options and Targets from command-line (see Sample2).

RegisterCommand

There is another option how to resolve Commands: Commander.RegisterCommand. More details to be provided (see also Sample3).

Last updated