GnuGetOpt 1.1.3
dotnet add package GnuGetOpt --version 1.1.3
NuGet\Install-Package GnuGetOpt -Version 1.1.3
<PackageReference Include="GnuGetOpt" Version="1.1.3" />
<PackageVersion Include="GnuGetOpt" Version="1.1.3" />
<PackageReference Include="GnuGetOpt" />
paket add GnuGetOpt --version 1.1.3
#r "nuget: GnuGetOpt, 1.1.3"
#:package GnuGetOpt@1.1.3
#addin nuget:?package=GnuGetOpt&version=1.1.3
#tool nuget:?package=GnuGetOpt&version=1.1.3
GnuGetOpt
C#.NET port of Java port of GNU getopt from glibc 2.0.6
Installation
dotnet add package GnuGetOpt
Usage
Short options
Parse command-line options using a format string where each character is a valid option. A colon after a character means the option requires an argument. Two colons mean the argument is optional.
using Gnu.Getopt;
var g = new Getopt("myapp", args, "ab:c::d");
int c;
while ((c = g.getopt()) != -1)
{
switch (c)
{
case 'a':
case 'd':
Console.WriteLine("Option: " + (char)c);
break;
case 'b':
case 'c':
Console.WriteLine("Option: " + (char)c + " Arg: " + g.Optarg);
break;
case '?':
// getopt() already printed an error
break;
}
}
// Remaining non-option arguments
for (int i = g.Optind; i < args.Length; i++)
{
Console.WriteLine("Argument: " + args[i]);
}
$ myapp -a -b value -d file1 file2
Option: a
Option: b Arg: value
Option: d
Argument: file1
Argument: file2
Long options
Define long options using LongOpt objects. Each long option maps to a short option character or a custom integer value.
using Gnu.Getopt;
using System.Text;
var longopts = new LongOpt[]
{
new LongOpt("help", Argument.No, null, 'h'),
new LongOpt("output", Argument.Required, null, 'o'),
new LongOpt("verbose", Argument.No, null, 'v'),
};
var g = new Getopt("myapp", args, "ho:v", longopts);
int c;
while ((c = g.getopt()) != -1)
{
switch (c)
{
case 'h':
Console.WriteLine("Help requested");
break;
case 'o':
Console.WriteLine("Output: " + g.Optarg);
break;
case 'v':
Console.WriteLine("Verbose mode");
break;
}
}
$ myapp --verbose --output=result.txt input.txt
Verbose mode
Output: result.txt
Option string format
| Format | Meaning |
|---|---|
a |
Option -a, no argument |
b: |
Option -b, required argument |
c:: |
Option -c, optional argument |
:abc |
Return : instead of ? for missing arguments |
+abc |
POSIX mode: stop at first non-option |
-abc |
Return in order: non-options returned as argument to option 1 |
Properties
| Property | Description |
|---|---|
Optarg |
The argument value for the current option |
Optind |
Index of the next element to be processed in argv |
Optopt |
The option character that caused an error |
Opterr |
Set to false to suppress error messages |
Longind |
Index into the long option array of the last long option found |
Breaking changes in 1.0.0
Nullable reference types
All projects now have <Nullable>enable</Nullable>. Properties that can be null are annotated:
Getopt.Optargis nowstring?LongOptconstructorflagparameter acceptsStringBuilder?
Renamed types (ConsoleApplication only)
The demo application types were renamed to follow .NET conventions:
| Before | After |
|---|---|
ActionEnum |
ProgramAction |
CidrParseEnum |
CidrParseMode |
Namespace changes (ConsoleApplication only)
| Before | After |
|---|---|
System.Net.ConsoleApplication |
ConsoleApplication |
System.Net.TestProject |
TestProject |
Removed legacy CI
AppVeyor, Travis CI, and Coveralls configurations have been removed. CI/CD is now handled entirely by GitHub Actions.
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 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. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on GnuGetOpt:
| Repository | Stars |
|---|---|
|
lduchosal/ipnetwork
IPNetwork command line and C# library take care of complex network, IP, IPv4, IPv6, netmask, CIDR, subnet, subnetting, supernet, and supernetting calculation for .NET developers. It works with IPv4 as well as IPv6, is written in C#, has a light and clean API, and is fully unit-tested
|