Skip to content

NDesk.Options is a callback-based program option parser for C#.

License

Notifications You must be signed in to change notification settings

Latency/NDesk.Options.Core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NDesk.Options

A callback-based program option parser for C#.


Description
CREATED BY: [Latency McLaughlin]
UPDATED: 9/18/2024
FRAMEWORK: net452, netstandard2.0, netstandard2.1, net9.0
LANGUAGE: [C#] preview
OUTPUT TYPE: Library [API]
SUPPORTS: [Visual Studio]
GFX SUBSYS: [None]
TAGS: [NDesk.Options C#]
STATUS:
LICENSE:
VERSION:

Navigation


It takes advantage of C# features such as collection initializers and lambda delegates to provide a short, concise specification of the option names to parse, whether or not those options support values, and what to do when the option is encountered. It's entirely callback based:

See: http://www.ndesk.org/Options

var verbose = 0;
var show_help = false;
var names = new List<string> ();

var p = new OptionSet () {
  { "v|verbose", v => { if (v != null) ++verbose; } },
  { "h|?|help",  v => { show_help = v != null; } },
  { "n|name=",   v => { names.Add (v); } },
};
int          verbose   = 0;
bool         show_help = false;
List<string> names     = new List<string> ();

OptionSet p = new OptionSet ()
  .Add ("v|verbose", delegate (string v) { if (v != null) ++verbose; })
  .Add ("h|?|help",  delegate (string v) { show_help = v != null; })
  .Add ("n|name=",   delegate (string v) { names.Add (v); });

This library can be installed using NuGet found here.

The source code for the site is licensed under the MIT license, which you can find in the MIT-LICENSE.txt file.

All graphical assets are licensed under the Creative Commons Attribution 3.0 Unported License.