Optionus 0.9.0
dotnet add package Optionus --version 0.9.0
NuGet\Install-Package Optionus -Version 0.9.0
<PackageReference Include="Optionus" Version="0.9.0" />
<PackageVersion Include="Optionus" Version="0.9.0" />
<PackageReference Include="Optionus" />
paket add Optionus --version 0.9.0
#r "nuget: Optionus, 0.9.0"
#:package Optionus@0.9.0
#addin nuget:?package=Optionus&version=0.9.0
#tool nuget:?package=Optionus&version=0.9.0
Optionus
A small, dependency-free command-line option parser for .NET, in the style of Perl's Getopt::Long.
Optionus is a maintained fork of Mono.Options, which itself grew out of NDesk.Options. Both upstream projects are no longer actively maintained. Optionus keeps the API and behaviour, targets current .NET, and fixes a few long-standing issues.
Authors and credits
Optionus is based on the work of the original authors:
- Jonathan Pryor: original author of NDesk.Options and Mono.Options
- Federico Di Gregorio: contributor
- Rolf Bjarne Kvinge: contributor (Xamarin)
- Novell, Xamarin Inc and Microsoft Corporation: copyright holders of the upstream code
Fork maintained by vdasus.
Features
- Single source file, no dependencies
- Option prototypes:
"v|verbose","n|name="(required value),"l|level:"(optional value) - Short, long and Windows-style prefixes:
-v,--verbose,/verbose - Values as
-n=foo,-n:foo,-n foo - Bundling:
-abcis the same as-a -b -c;-Dname=value - Boolean switches:
-x+/-x- - Typed values through
TypeConverter:int,enum,Nullable<T>, custom types - Key/value options:
-Dkey=value --stops option processing- Response files:
@args.txt - Generated help text:
WriteOptionDescriptions - Git-style sub-commands with
CommandSetandCommand
Target frameworks
netstandard2.0(.NET Framework 4.6.1+, .NET Core 2.0+, Mono)net10.0
Installation
dotnet add package Optionus
Quick start
using Optionus;
bool showHelp = false;
int verbosity = 0;
string? output = null;
var names = new List<string>();
var options = new OptionSet {
"Usage: greet [OPTIONS]+ NAME...",
"",
"Options:",
{ "n|name=", "the {NAME} to greet", v => names.Add(v) },
{ "o|output=", "write to {FILE}", v => output = v },
{ "v", "increase verbosity", v => { if (v != null) ++verbosity; } },
{ "h|help", "show this message and exit", v => showHelp = v != null },
};
List<string> extra;
try {
extra = options.Parse(args);
}
catch (OptionException e) {
Console.Error.WriteLine($"greet: {e.Message}");
Console.Error.WriteLine("Try `greet --help' for more information.");
return 1;
}
if (showHelp) {
options.WriteOptionDescriptions(Console.Out);
return 0;
}
Parse returns the arguments it did not consume.
Sub-commands
var suite = new CommandSet("tool") {
"usage: tool COMMAND [OPTIONS]+",
new Command("build", "Build the project") {
Options = new OptionSet { { "c|configuration=", v => configuration = v } },
Run = args => Build(args),
},
};
return suite.Run(args);
tool help and tool help build are provided automatically.
Migrating from NDesk.Options or Mono.Options
Replace the package reference and the namespace:
- using NDesk.Options;
- using Mono.Options;
+ using Optionus;
The public API is otherwise unchanged.
Changes compared to Mono.Options
- Namespace
Optionus; SDK-style project fornetstandard2.0andnet10.0 - Breaking: typed values (
int,double,DateTime, …) are converted with the invariant culture, so-r=1.5means 1.5 on every machine. Mono.Options used the current culture, where1.5fails on a machine with a decimal comma (lt-LT,de-DE, …) - Response files are closed when parsing fails part-way; previously the file handle stayed open until garbage collection
ArgumentSource.GetArgumentsFromFileopens the file on first enumeration, so an enumerable that is never enumerated does not leak a handle- A response file that includes itself, directly or indirectly, raises
OptionExceptioninstead of recursing until resources run out (nesting limit: 64) CommandSet.GetCompletionshandles a prefix with leading whitespace correctly- The "Found {0} option values" error message is now passed to the message localizer before formatting, consistent with the other messages
- Binary serialization members of
OptionExceptionare only compiled fornetstandard2.0(formatter-based serialization is obsolete on .NET 8+) - Tests ported from NUnit to xUnit v3
Building and testing
dotnet build
dotnet test
Requires the .NET 10 SDK.
License
MIT. See LICENSE. The original copyright notices are kept in the source file and in the license.
| Product | Versions 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 is compatible. 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. |
-
.NETStandard 2.0
- No dependencies.
-
net10.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 |
|---|---|---|
| 0.9.0 | 229 | 10/22/2026 |