NFlags 1.0.0

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

// Install NFlags as a Cake Tool
#tool nuget:?package=NFlags&version=1.0.0

NFlags

Simple library to made parsing CLI arguments easy. Library also allow You to print usage help "out of box".

For example of usage check Examples directory.

Basics

Set app name

Name set with folowing code, will be printed in help. By default AppDomain.CurrentDomain.FriendlyName is used.

NFlags.Configure(configurator => configurator.SetName("Custom Name"));

Set app description

Description set with folowing code, will be printed in help.

NFlags.Configure(configurator => configurator.SetDescription("App description"));

Set flag

Flag is an prefixed argument without value. It can be turned on or off. Flag abreviation can be also set.

NFlags.Configure(configurator => configurator.RegiasterFlag("flag", "f", "Flag description", () => flagVariable = true));
NFlags.Configure(configurator => configurator.RegiasterFlag("flag", "Flag description", () => flagVariable = true));

Set option

Option is an prefixed argument with value. Flag abreviation can be also set.

NFlags.Configure(configurator => configurator.RegiasterOption("option", "o", "option description", v => optionVariable = v));
NFlags.Configure(configurator => configurator.RegiasterOption("option", "option description", v => optionVariable = v));

Set parameter

Parameter is an unprefixed value argument. Parameters are read by registration order.

NFlags.Configure(configurator => configurator.RegiasterParam("param", "Param description", v => paramVariable = v));

Parsing arguments

To parse arguments call:

NFlags.Configure(configurator => {}).Read(args);

Dialects

Dialect defines how flags and options are prefixed and how option value follows option. By default 2 dialect are suported: Gnu, Win

Dialect can be set (default is Win) using:

NFlags.Configure(configurator => configurator.SetDialect(Dialect.Gnu));

Dialects can be easly extended. To create new dialect simply create new class inherited from Dialect class.

    public class CustomDialect : Dialect
    {      
        public override string Prefix => "x";

        public override string AbrPrefix => "a";

        public override OptionSeparator OptionSeparator => OptionSeparator.ArgSeparator;
    }

and configure NFlags using it

NFlags.Configure(configurator => configurator.SetDialect(new CustomDialect()));

Win dialect

Win dialect, follows MS Windows standards for definig console app arguments:

  • Flags and flags abreviations are prefixed by '/'
  • Options and options abreviations are prefixed by '/'
  • Value follow option after '='

Gnu dialect

Gnu dialect, follows Gnu Linux standards for definig console app arguments:

  • Flags are prefixed by '--'
  • Flags abreviations are prefixed by '-'
  • Options are prefixed by '--'
  • Options abreviations are prefixed by '-'
  • Value follow option as next argument after option

Help

Help generation is suported "out of box" and it follows dialect rules. To print help use:

Console.WriteLine(NFlags.Configure(configurator => {}).PrintHelp());

Example help for Win dialect:

Usage:
        NFlags.Win [FLAGS]... [OPTIONS]... [PARAMETERS]...

Application description

        Flags:
        /help, /h       Print this help
        /verbose, /v    Verbose description
        /clear  Clear description

        Options:
        /option1=<option1>, /o1=<option1>       Option 1 description
        /option2=<option2>      Option 2 description

        Parameters:
        <param1>        Parameter 1 description

and for Gnu dialect:

Usage:
        NFlags.Gnu [FLAGS]... [OPTIONS]... [PARAMETERS]...

Application description

        Flags:
        --help, -h      Print this help
        --verbose, -v   Verbose description
        --clear Clear description

        Options:
        --option1 <option1>, -o1 <option1>      Option 1 description
        --option2 <option2>     Option 2 description

        Parameters:
        <param1>        Parameter 1 description

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 (7)

Showing the top 5 NuGet packages that depend on NFlags:

Package Downloads
NetMicro.MongoDB.NFlags

Package Description

NetMicro.RabbitMQ.NFlags

Package Description

NetMicro.Monitoring.Prometheus.NFlags

Package Description

NetMicro.Auth.Jwt.NFlags

Package Description

NetMicro.Consul.NFlags

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.10.0 862 12/20/2021
1.9.0 456 11/15/2020
1.8.0 669 3/15/2020
1.7.2 1,877 11/3/2019
1.7.1 5,079 6/27/2019
1.7.0 701 4/7/2019
1.6.0 728 2/18/2019
1.5.0 751 2/2/2019
1.4.0.1 800 11/16/2018
1.4.0 788 11/14/2018
1.3.1 809 11/9/2018
1.3.0 787 11/2/2018
1.2.1 852 8/22/2018
1.1.1 1,131 12/15/2017
1.1.0-rc 1,335 11/3/2017
1.0.0 1,312 11/1/2017