I\'m looking for a getopt library for c#. So far I found a few (phpguru, XGetOptCS, getoptfordotnet) but these look more like unfinished attempts that only support a part of
A friend of mine suggested docopt.net, a command-line argument parsing library based on the docopt library for Node.JS. It is very simple to use, yet advanced and parses arguments based on the help string you write.
Here's some sample code:
using System;
using DocoptNet;
namespace MyProgram
{
static class Program
{
static void Main(string[] args)
{
// Usage string
string usage = @"This program does this thing.
Usage:
program set
program do [-o ]
program do [somethingelse]";
try
{
var arguments = new Docopt().Apply(usage, args, version: "My program v0.1.0", exit: false);
foreach(var argument in arguments)
Console.WriteLine("{0} = {1}", argument.Key, argument.Value);
}
catch(Exception ex)
{
//Parser errors are thrown as exceptions.
Console.WriteLine(ex.Message);
}
}
}
}
You can find documentation for it (including its help message format) at both the first link and here.
Hope it helps someone!