Best Argument-Processing for .NET/C#

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")]
            string projectPath,

            [Description("Package name")]
            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.

One thought on “Best Argument-Processing for .NET/C#

Comments are closed.