Cliargs.NET 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Cliargs.NET --version 1.0.1
NuGet\Install-Package Cliargs.NET -Version 1.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="Cliargs.NET" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cliargs.NET --version 1.0.1
#r "nuget: Cliargs.NET, 1.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 Cliargs.NET as a Cake Addin
#addin nuget:?package=Cliargs.NET&version=1.0.1

// Install Cliargs.NET as a Cake Tool
#tool nuget:?package=Cliargs.NET&version=1.0.1

Command Line Interface Arguments parser for C#

.NET NuGet Badge
License

image Build history

Cliargs.NET is a .NET library helps you to parse and use the Command Line Interface arguments in easy way.

The main goal of Cliargs.NET is to help C# developers reduce their programming time without dealing with all validations and casting of the user input.

Cliargs.NET makes all for you, all you have to do is write your Setup configuration in order to configure the Arguments container, then, from key and values parsing, to validation is automatically done on app startup.

Quick comparison

In this example, you see the difference between managing the command line arguments by yourself, or by Cliargs.NET, for an application with two arguments:

Argument         type key short key Optional
User Name string --name -n no
User age uint --age -a yes

The objective is to display the following message in a console app:

Dear {user name}, you're {user age} years old!

Example of old school way: 😔

👉 Example on gist 👈

New way with Cliargs.NET 🤩

Create your Setup class and implement the Configure method to create your app arguments:

public class CliArgsSetup : ICliArgsSetup
{
    public void Configure(ICliArgsContainer container)
    {
        var nameArg = CliArg.New<string>("name")
            .AsRequired()
            .WithShortName("n");

        var ageArg = CliArg.New<uint>("age")
            .AsOptional()
            .WithShortName("a");

        container.Register(nameArg);
        container.Register(ageArg);
    }
}

Initialize the AppCliArgs instance by calling Initialize method at the begining of your app main method:

AppCliArgs.Initialize<CliArgsSetup>(new CustomFormat());

The finally start using the arguments values

var name = AppCliArgs.GetArgValue<string>("name");
if (AppCliArgs.IsSet("age"))
{
    var age = AppCliArgs.GetArgValue<uint>("age");
    Console.WriteLine($"Dear {name}, you're {age} years old.");
}
else
{
    Console.WriteLine($"Dear {name}, we don't know your age!");
}

Documentation

More examples and documentation is on Wiki

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 5,331 4/2/2022
1.2.3 393 3/20/2022
1.0.1 418 2/23/2022