Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Exact Mirror of ndesk-options on github. Cause I don't want to remember too many URLs. This is a good optparse implementation in C#. See the original homepage for details.
JavaScript Shell
tree: 9e1277ac27

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc
lib
src/NDesk.Options
.gitignore
AUTHORS
COPYING
ChangeLog
INSTALL
Makefile.am
NEWS
README
autogen.sh
configure.ac
ndesk-options.spec.in

README

NDesk.Options
=============

NDesk.Options is a program option parser for C#.

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

Overview:
--------

It takes advantage of C# 3.0 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:

	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); } },
	};

However, C# 3.0 features are not required, and can be used with C# 2.0:

	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); });


Variants:
--------

In order to cut down on the number of unique types (and the combinatorial
explosion that produces when trying to mix-and-match delegate types),
NDesk.Options "uses" some .NET 3.5 types.  

Normally, this would prevent .NET 2.0 support.

So to support both .NET 2.0 and .NET 3.5, NDesk.Options can be built in two
separate ways:

	- With LINQ `#define`d: .NET 3.5 is assumed.
	- With LINQ `#undef`ined: .NET 2.0 is assumed.

When LINQ is not defined, the System.Action<T1,T2> type is present within
NDesk.Options.dll.  Consequently, to prevent ambiguous type conversions, you
should only use the LINQ version on .NET 3.5, and the non-LINQ version on 
.NET 2.0.


Distribution:
------------

In accordance with the Guidelines for Application Deployment [0], there are
pkg-config files to permit simple access to the source or pre-compiled
assemblies for re-use.

There are three ways to use NDesk.Options:

	- Bundle src/NDesk.Options/NDesk.Options/Options.cs with your app.
	  You should #define LINQ as appropriate, depending on whether you
	  target .NET 2.0 or .NET 3.5 (as described above).  Source is readily
	  obtained via:

		pkg-config --variable=Sources ndesk-options

	- Use the .NET 2.0-specific NDesk.Options.dll:

		pkg-config --variable=Libraries ndesk-options

	- Use the .NET 3.5-specific NDesk.Options.dll:

		pkg-config --variable=Libraries ndesk-options-linq


[0] http://www.mono-project.com/Guidelines:Application_Deployment#Libraries_with_Unstable_APIs
Something went wrong with that request. Please try again.