This framework I have used extensively and have been pretty happy with the results. I has its caveats, and that’s the reason this is not my last post of the series
As opposed to Mono.Options, it does not rely on upfront definition of arguments, but in decoration of methods and arguments. We can infer that multiple commands are supported out-of-the box, each corresponding to a method decorated with the
The definition of the commands is easily done inside any class:
And the entry point of the program is just a mere one-liner:
Mandatory arguments are decorated with the
RequiredAttribute and position matters (they must occur before any non-required one). The framework was able to report missing mandatory arguments:
As simple as declaring the right type for the method argument. NConsoler does not fail as gracefully as it ought to, but shows an exception that points out in the right direction:
List of arguments are supported out-of-the-box by separating the different values with the plus (+) sign:
Running the program without arguments shows a very descriptive list of available commands.
Which can be extended down to the command level by prefixing help to the specific command:
A potential problem may come from the fact that help information comes from text in attributes. That means they have to be constant; ruling out displaying information coming from a .resx file or use any sort of localization.
The concept of a command (a subcommand or action as they call it) is a central concept for NConsoler, so dispatching is baked in, simple and quite well executed: a command is a method, and its argument list, the parameters to be parsed.
Being the command name the name of a method, rules out command names that are not valid method identifiers in .NET. It may not be a big deal, but definitely something to keep in mind (in my example I had to change the dash in something-else by and underscore).
Having used NConsoler as a framework for my quick-and-not-so-dirty console applications and being aware of its limitations, I cannot see myself not considering it as a viable alternative. But today, it would not be my weapon of choice.
Which one will be? Wait and see…