J4JSoftware.Configuration.CommandLine 4.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package J4JSoftware.Configuration.CommandLine --version 4.0.1                
NuGet\Install-Package J4JSoftware.Configuration.CommandLine -Version 4.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="J4JSoftware.Configuration.CommandLine" Version="4.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add J4JSoftware.Configuration.CommandLine --version 4.0.1                
#r "nuget: J4JSoftware.Configuration.CommandLine, 4.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install J4JSoftware.Configuration.CommandLine as a Cake Addin
#addin nuget:?package=J4JSoftware.Configuration.CommandLine&version=4.0.1

// Install J4JSoftware.Configuration.CommandLine as a Cake Tool
#tool nuget:?package=J4JSoftware.Configuration.CommandLine&version=4.0.1                

J4JCommandLine

A Net5 library which adds parsing command line arguments to the IConfiguration system. Command line arguments can be bound to instance or static properties of classes, including nested classes.

There are some restrictions on the nature of the target classes, mostly having to do with them having public parameterless constructors. This is the same constraint as exists for the IConfiguration system.

The libraries are licensed under the GNU GPL-v3 or later. For more details see the license file.

There are breaking changes in the latest release. Please review the documentation.

For more information consult the github documentation.

TL;DR

static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .AddJ4JCommandLineForWindows( out var options, out _ )
        .Build();

    options!.Bind<Program, int>(x => Program.IntValue, "i")!
        .SetDefaultValue(75)
        .SetDescription("An integer value");

    options.Bind<Program, string>(x => Program.TextValue, "t")!
        .SetDefaultValue("a cool default")
        .SetDescription("A string value");

    options.FinishConfiguration();

    var help = new ColorHelpDisplay(new WindowsLexicalElements(), options);
    help.Display();

    var parsed = config.Get<Program>();

    if (parsed == null)
    {
        Console.WriteLine("Parsing failed");

        Environment.ExitCode = -1;
        return;
    }

    Console.WriteLine("Parsing succeeded");

    Console.WriteLine($"IntValue is {IntValue}");
    Console.WriteLine($"TextValue is {TextValue}");

    Console.WriteLine(options.SpuriousValues.Count == 0
        ? "No unkeyed parameters"
        : $"Unkeyed parameters: {string.Join(", ", options.SpuriousValues)}");
}

public static int IntValue { get; set; }
public static string TextValue { get; set; }

This example can be simplified further by using my dependency injection library. There is also a TryBind<...>() method which you can use as an alternative to Bind<...>().

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on J4JSoftware.Configuration.CommandLine:

Package Downloads
J4JSoftware.DependencyInjection

provides customized IHostBuilder and IHost classes for simplified configuration

J4JSoftware.Configuration.J4JCommandLine.ColorfulHelp

colorful help formatter for the J4JCommandLine system

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.3.0 378 4/4/2023
4.2.0 458 12/27/2022
4.1.1 486 2/28/2022
4.1.0 624 11/13/2021
4.0.1 1,153 9/29/2021
4.0.0 1,184 9/28/2021
1.1.1 473 2/3/2021
1.1.0 419 1/21/2021
1.0.0 427 1/9/2021

added nuget readme