CommandLineArgsHelper 1.0.0.4

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

// Install CommandLineArgsHelper as a Cake Tool
#tool nuget:?package=CommandLineArgsHelper&version=1.0.0.4

CommandLineArgsHelper

A parsing class to dramatically simplify working with command line arguments in a .Net application (e.g. console, client, or even web application).

It supports a variety of parameter syntaxes, and seamlessly parses all of them into a simplified Dictionary interface of key value string pairs.

Why another Library?

Many of the existing libraries are based on the constrained paradigm that arguments should be bound to strongly typed objects. However, for many implementations, this is a limiting approach that means you have to re-compile the app to support new parameters; not supporting dynamic behavior, and possibly making the model that params bind to force you to have strange naming conventions in your code.

Instead, this provides a loosely coupled approach that is more generic and allows you to support dynamic behavior and strongly typed behavior (by simply putting keys into property getter's if you like).

Original Code forked from:

The Code has been adapted from the original source located at: https://www.codeproject.com/Articles/3111/C-NET-Command-Line-Arguments-Parser

But it has been updated and simplified as follows:

  • Updated with new C# syntax
  • More robust parsing for wider array of parameter syntaxes, keys/values with spaces, etc.
  • Enhanced class wrapper (e.g. exposed read only dictionary for enumeration)
  • Support for both key/value parameter pairs, as well as simple boolean flags (param is defined/exists or not)
  • Improved thread safety
  • Eliminated code duplication

Usage:

Usage is extremely simple:

//Intialize given a string array of arguments (string[])...
//  1) injected into console app main routine
//  2) accessed via Environment.GetCommandLineArgs()
var commandLineArgHelper = new CommandLineArgsHelper(args);

var value = commandLineArgsHelper["paramKeyName"];

Console.WriteLine($"paramKeyName == {value]")

Example:

Command line with all of the following (mixed syntaxes fully supported):

-size=100 /height:'400' /day:"happy birthday" -tgif="Thank God It's Friday" -AmINice "Nice stuff !" 
--debug -param1 value1 --param2Alone /param3:"Test-:-work" /param4=--value4-- -param5 "--=nice=--"
/"param6 with spaces"="Spaces are A-OK!"

Will result in an easily accesible set of values as follows: Command Line Arguments:

  1. [size] == [100]
  2. [height] == [400]
  3. [day] == [happy birthday] //Complex value with spaces in the value
  4. [tgif] == [Thank God It's Friday] //Complex value with spaces & apostrophe (special characters) in the value
  5. [AmINice] == [Nice stuff !]
  6. [debug] == [true] //Boolean flag if a standalone param key is defined
  7. [param1] == [value1]
  8. [param3] == [Test-:-work] //Complex value with colon (special characters) in the value
  9. [param2Alone] == [true] //Boolean flag if a standalone param key is defined
  10. [param4] == [--value4--] //Complex value with dashes (special characters) in the value
  11. [param5] == [--=nice=--] //Complex value with equal sign (special characters) in the value
  12. [param6 with spaces] == [Spaces are A-OK!] //Complex Keys or Values that have spaces


/*
MIT License

Copyright (c) 2019 Brandon Bernard

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
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. 
.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.0.0.5 752 7/24/2020
1.0.0.4 500 10/25/2019
1.0.0.3 477 10/23/2019

Migrate assembly to target .Net Standard 2.0 for greater compatibility with .Net Framework 4.7.2+ and .Net Core 2.0+; No functionality changes.