ScottLilly.ArgumentParser 1.1.1

dotnet add package ScottLilly.ArgumentParser --version 1.1.1
                    
NuGet\Install-Package ScottLilly.ArgumentParser -Version 1.1.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="ScottLilly.ArgumentParser" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ScottLilly.ArgumentParser" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="ScottLilly.ArgumentParser" />
                    
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 ScottLilly.ArgumentParser --version 1.1.1
                    
#r "nuget: ScottLilly.ArgumentParser, 1.1.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 ScottLilly.ArgumentParser@1.1.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=ScottLilly.ArgumentParser&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=ScottLilly.ArgumentParser&version=1.1.1
                    
Install as a Cake Tool

Build Status

ScottLilly.ArgumentParser

A lightweight C# NuGet package for parsing a string, or array of strings (such as command-line arguments) into a ParsedArguments object. It categorizes arguments into their types, including all arguments, integers, decimals, strings, named key/value pairs, and enum-based arguments.

Installation

Install the package via NuGet Package Manager or use the following command in the Package Manager Console:

Install-Package ScottLilly.ArgumentParser

Or via the .NET CLI:

dotnet add package ScottLilly.ArgumentParser

Features

Instantiate a Parser object to parse strings or arrays of strings into a ParsedArguments object. Pass the optional array of characters or strings to use to separate arguments in the string and/or to separate key/value pair arguments.

How to use

Code samples:

Parse a string with various argument types

var parser = new Parser();

var parsedArguments = parser.Parse("123 45.67 hello world --key=value");

Assert.Equal(5, parsedArguments.Arguments.Count);
Assert.Equal(1, parsedArguments.IntegerArguments.Count);
Assert.Equal(1, parsedArguments.DecimalArguments.Count);
Assert.Equal(3, parsedArguments.StringArguments.Count);
Assert.Equal(1, parsedArguments.NamedArguments.Count);
Assert.Equal("value", parsedArguments.NamedArguments["key"]);

Parse values that should match an enum type

public enum EmployeeType
{
    Production,
    Sales,
    Marketing,
}

var parser = new Parser();

var parsedArguments =
    parser.Parse("production sales marketing");

Assert.Equal(3, parsedArguments.Arguments.Count);
Assert.Empty(parsedArguments.IntegerArguments);
Assert.Empty(parsedArguments.DecimalArguments);
Assert.Equal(3, parsedArguments.StringArguments.Count);
Assert.Equal(3, parsedArguments.EnumArgumentsOfType<EmployeeType>().Count());

Use fluent interface to parse arguments

ParsedArguments parsedArguments =
    FluentArgumentParser
    .Create()
    .AddArgumentSeparators(new string[] { "--", "-" })
    .AddKeyValueSeparators(new char[] { ':', '|' })
    .Parse(@"--solution:value1 -s|value2");

Assert.Equal(2, parsedArguments.Arguments.Count);
Assert.Equal("value1", parsedArguments.NamedArguments["solution"]);
Assert.Equal("value2", parsedArguments.NamedArguments["s"]);

Use fluent interface to initialize parser, then parse arguments

var initializedParser = 
    FluentArgumentParser
    .Create()
    .AddArgumentSeparators(new string[] { "--", "-" })
    .AddKeyValueSeparators(new char[] { ':', '|' });

ParsedArguments parsedArguments =
    initializedParser.Parse(@"--solution:value1 -s|value2");

Assert.Equal(2, parsedArguments.Arguments.Count);
Assert.Equal("value1", parsedArguments.NamedArguments["solution"]);
Assert.Equal("value2", parsedArguments.NamedArguments["s"]);

Requirements

  • .NET Standard 2.0 or higher
  • No external dependencies.

Contributing

Contributions are welcome. Please submit issues or pull requests to the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or feedback, please open an issue here on GitHub.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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.  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 was computed. 
.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 was computed.  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.
  • .NETStandard 2.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.1.1 219 4/20/2025
1.0.0 236 1/3/2024

Fix issue with command line key/value arguments, which were already split in app's static Main method.