| GetOpt# 0.1 |
I'm in need of something like getopt for C#, and couldn't find one Googling. getopt provides standard Unix style command line parsing, which is what this version does as well. This version is very simple and only implements the short version of command line options. I'll implement long command line options later...
Here's a sample usage:
bool verbose = false;
string input = "";
if(args.Length == 0)
{
Console.WriteLine("Usage: openpdfdescribe -v -i <input pdf>");
return;
}
GetOpt options = new GetOpt(args, "vi:");
Arg a = options.NextArg();
while(a != null)
{
switch(a.Flag)
{
case "-v":
verbose = true;
break;
case "-i":
input = a.Parameter;
break;
default:
Console.WriteLine("Unknown command line option: " + a.Flag);
Console.WriteLine("Usage: openpdfdescribe -v -i <input pdf>");
return;
}
a = options.NextArg();
}
Console.WriteLine("Verbose = " + verbose);
Console.WriteLine("Input = " + input);
This code is released under the terms of the GNU LGPL. You can download the code from here.
Technorati tags for this post: getopt dotnet c# opensource
posted at: 17:30 | path: /getopt | permanent link to this entry
There are no comments on this post which have survived moderation. 5 posts have been culled and 6 blocked. Be the first to make a non-spam comment here, please!
