After trying NDesk.Options and Fluent, I am nothing but impressed with CLAP (“Command-Line Auto-Parser”). It completely relies on reflection and parameter attributes (usually just one or two) to automatically marshal your values, assign defaults, enforce requiredness, and provide command-line documentation. It’s beautiful and, so far, flawless. Well done.
using CLAP;
namespace MyNamespace
{
class Program
{
[Verb(IsDefault = true, Description = "Print the current version of the given package and, optionally, increment it.")]
public void Version(
[Description("Project path")]
[Required]
string projectPath,
[Description("Package name")]
[Required]
string packageName,
[Description("Base version to increment from (if lower than current, else use current)")]
string baseVersion = null,
[Description("Increment the version before returning")]
bool increment = false
)
{
// ...
}
}
}
If you don’t decorate with the “Required” attribute and don’t provide a default value the parameter will default to null. I explicitly set baseVersion to a default of null because I prefer being explicit.
FYI… I have been using PowerArgs for many years and find it robust, extensible and mature. I tried several including writing my own but I find PowerArgs the perfect blend between ease of usability and extensibility when hitting an edge case.
http://www.nuget.org/packages/PowerArgs/
LikeLike