ArgsNET 1.0.1

dotnet add package ArgsNET --version 1.0.1                
NuGet\Install-Package ArgsNET -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="ArgsNET" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ArgsNET --version 1.0.1                
#r "nuget: ArgsNET, 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 ArgsNET as a Cake Addin
#addin nuget:?package=ArgsNET&version=1.0.1

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

ArgsNET

A .NET command line argument parser. It can be used without any configuration, as long as you have a class that can receive the data. For example:

var arguments = ArgsNET.Deserialize.SystemArguments().To<Arguments>(out var errors);

This assumes we have a class along the lines of this:

class Arguments
{
    public bool help;
    public string[] input;
    public string output;
}

The above would be able to parse any of the following automatically:

Variable CLI arguments Accepts value
Arguments.help -h / --help No
Arguments.input -i / --input Yes, like -i index.html index.js index.css
Arguments.output -o / --output Yes, like -o build/index.html

Detailed information

Flags

All booleans are understood as flags. A flag does not accept a value, and is instead called just with the argument, like -v or --help. When this happens, the relevant boolean field or property will be set to true.

Note that flags may only be set once, multiple arguments of the same flag, like -h -h, will cause a parse error to be returned, marking the second instance as incorrect.

Options

All non-booleans are understood as options. These may accept one or multiple values, depending on if they are arrays (any other collection), or if they are a regular value like just a string or int. The regular values may only be set once, just like flags. Arrays and lists, however, may be set as many times as desired. This can be done with any of the following methods:

Multi-value method Example
Space separated -i value1 value2 value3
Comma separated -i=value1,value2,value3
Multiple arguments -i value1 -i value2 -i value3

Argument names

If nothing else is specified the argument names are resolved by using the field or property name into a long and short version. The long names are resolved first, and will be formatted as this:

Variable name Argument name
example --example
FieldExample --field-example
PropertyExample --property-example
nameWith123Numbers --name-with-123-numbers

The short name, meanwhile, is resolved by using the long name above and trimming it to only use the first letter of each section, like this:

Long name Short name
--example -e
--really-verbose-name -rvn
--name-with-123-numbers -nw1n
Custom argument names

It is possible to define custom names, instead of using the automatic name resolver by using the ArgumentName attribute:

[ArgumentName("o", "output")]
public string output;

[ArgumentName("r", "hot-reload")]
public bool hotReload;

Note that we do not add any hyphens at the start of the name. Those will be added automatically.

It is also possible to only set the long argument, and have the short one be automatically generated:

[ArgumentName("output")] // Short = "-o"
public string output;

[ArgumentName("hot-reload")] // Short = "-hr"
public bool hotReload;

Deserializer options

There are three ways to deserialize arguments:

Method Example Description
SystemArguments Deserialize.SystemArguments() Uses the arguments given to the application
String Deserialize.String("-o example.txt") Uses a raw string
Arguments Deserialize.Arguments(someArgs) Uses a string array

In most cases the regular SystemArguments method will suffice, but in some cases you have different handling depending on the first argument, like npm install or git switch, where the first argument is not a flag. In these cases it's recommended to implement a switch on the first argument, and then use the Arguments method with the something like Deserialize.Arguments(args.Skip(1).ToArray()).

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.1 279 11/26/2023
1.0.0 102 11/26/2023 1.0.0 is deprecated.