SimpleCommandlineParser 1.4.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SimpleCommandlineParser --version 1.4.1
                    
NuGet\Install-Package SimpleCommandlineParser -Version 1.4.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="SimpleCommandlineParser" Version="1.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpleCommandlineParser" Version="1.4.1" />
                    
Directory.Packages.props
<PackageReference Include="SimpleCommandlineParser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimpleCommandlineParser --version 1.4.1
                    
#r "nuget: SimpleCommandlineParser, 1.4.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.
#:package SimpleCommandlineParser@1.4.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimpleCommandlineParser&version=1.4.1
                    
Install as a Cake Addin
#tool nuget:?package=SimpleCommandlineParser&version=1.4.1
                    
Install as a Cake Tool

SimpleCommandLineParser

Simple and straight forward command line parser for dotnet console apps.
Version 1.4.1 includes a refreshed list of target frameworks, and removes dependencies on a number of other libraries.

Breaking changes:

As of version 1.4.0...

  • the constructor wants an application name and description as parameters
  • the lambdas passed to the parameter methods are now Action<T> instead of Action<string>, T being the type of the parameter. This allows for better type checking and less casting.

Bug fixes:

Handle optional parameters.

Usage:

namespace UsageExample
{
    using System;
    using SimpleCommandlineParser;

    static class Program
    {

        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var parser = new Parser("SimpleCommandlineParser", "SimpleCommandlineParser usage example")
                .WithHelpWriter(Console.WriteLine)
                .WithErrorWriter(Console.Error.WriteLine)
                .AddHelpSwitch()
                .AddSwitch("mySwitch", () => Console.WriteLine($"Got a switch called mySwitch"), "command line switch")
                .AddStringParameter("Command", a => Console.WriteLine($"Command parameter: {a}"), "The command to be executed")
                .AddOptionalStringParameter("OptionalString", a => Console.WriteLine($"OptionalStringArgument: {a}"), "An optional String argument")
                .AddIntegerParameter("Number", a => Console.WriteLine($"Got a Number argument:{a}"), "An integer argument")
                .AddOptionalIntegerParameter("OptionalNumber", a => Console.WriteLine($"Got an optional Number argument:{a}"), "An optional integer argument")
                .AddDecimalParameter("Decimal", a => Console.WriteLine($"Got a Number argument:{a}"), "An Decimal argument")
                .AddOptionalDecimalParameter("OptionalDecimal", a => Console.WriteLine($"Got an optional Number argument:{a}"), "An optional Decimal argument")
                .AddDateParameter("Date", a => Console.WriteLine($"Got a Date argument:{a:D}"), "A date argument")
                .AddOptionalDateParameter("OptionalDate", a => Console.WriteLine($"Got an optional Date argument:{a}"), "An optional date argument")
                .AddDateTimeParameter("DateTime", a => Console.WriteLine($"Got a DateTime argument:{a:O}"), "A DateTime argument")
                .AddOptionalDateTimeParameter("OptionalDateTime", a => Console.WriteLine($"Got an optional DateTime argument:{a}"), "An optional DateTime argument")
                .Run(args);
                
            parser.EchoParameters();
            Console.WriteLine(parser.GetHelp());
            
        }
    }
}

When called as
UsageExample --MySwitch --number=1 --command=HelloWorld --decimal=3.14 --date=1961-12-28 --datetime=1961-12-28T18:00
the output of this simple console app would be:

Hello World!
Got a switch called mySwitch
Command parameter: HelloWorld
Got a Number argument:1
Got a Number argument:3.14
Got a Date argument:1961-12-28
Got a DateTime argument:1961-12-28T18:00:00.0000000
SimpleCommandlineParser running with parameters: --myswitch --number=1 --command=HelloWorld --decimal=3.14 --date=1961-12-28 --datetime=1961-12-28T18:00
SimpleCommandlineParser usage example
SimpleCommandlineParser usage is:
[--help]             : Get help on parameters
[--myswitch]         : command line switch
 --command           : The command to be executed
[--optionalstring]   : An optional String argument
 --number            : An integer argument
[--optionalnumber]   : An optional integer argument
 --decimal           : An Decimal argument
[--optionaldecimal]  : An optional Decimal argument
 --date              : A date argument
[--optionaldate]     : An optional date argument
 --datetime          : A DateTime argument
[--optionaldatetime] : An optional DateTime argument
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.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.4.2 161 4/21/2025
1.4.1 143 4/21/2025
1.4.0 145 4/21/2025
1.3.4 280 10/17/2023
1.3.3 121 10/17/2023
1.3.2 118 10/17/2023
1.3.1 109 10/17/2023
1.3.0 107 10/17/2023
1.2.0 1,223 5/24/2021
1.1.2 489 9/14/2020
1.1.1 476 9/14/2020
1.1.0 486 9/11/2020
1.0.0 513 9/11/2020

Release 1.2 introduced chainable methods to add parameters ane invoke parsing, lambdas and switch actions.
Release 1.4 refreshes the target frameworks and removes dependencies on 3rd party packages. Adding strong type checking on typed parameters (numbers and datetimes)