Daniel Drywa

GetOpts

A command line argument parser for C# and the .NET Standard 2.0

Description

This is a command line argument parser for C# and the .NET Standard 2.0. This parser is able to extract pre-defined options from a given enumerable of arguments.

Usage

For a proper introduction please take a look at the GitLab Repository. Add the NuGet package to your project references and you are ready to process command line arguments. Example:

using System;
using System.Linq;
using DD.GetOpts;

namespace Example {
    class Program {
        static void Main( string[] args ) {
            // Define argument options
            var option1 = new Option(
                "a", "alpha", Argument.NONE, Occur.ONCE );
            var option2 = new Option(
                "b", "beta", Argument.REQUIRED, Occur.OPTIONAL );
            var option3 = new Option(
                "g", "gamma", Argument.OPTIONAL, Occur.MULTIPLE );

            var options = new Options()
                .Add( option1 )
                .Add( options2 )
                .Add( options3 );

            // Parse arguments
            var matches = options.Parse( args );

            // Iterate through all argument matches
            foreach ( var match in matches ) {
                Console.WriteLine( $"Match for: {match.ShortName}" );
            }
        }
    }
}

Links

Description Link
Source Code Repository
NuGet Package nuget.org

30 September 2018