GnuGetOpt 1.1.3

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

GnuGetOpt

C#.NET port of Java port of GNU getopt from glibc 2.0.6

GitHub NuGet NuGet Downloads Build GitHub last commit License

Quality Gate Status Coverage Bugs Vulnerabilities Code Smells Maintainability Rating Reliability Rating Security Rating

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.Optarg is now string?
  • LongOpt constructor flag parameter accepts StringBuilder?

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

BSD-2-Clause

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 (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
Version Downloads Last Updated
1.1.3 278 4/4/2026
1.1.2 109 4/4/2026
1.1.1 103 4/4/2026
1.1.0 104 4/4/2026
1.0.1 116 4/4/2026
0.9.2.6 4,665 11/2/2022
0.9.2 559 11/2/2022