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.

    Tags for this post: getopt dotnet c# opensource
    Related posts: Profiling your code in mono; Regulator; A small example of how to find all the properties on an object using .NET reflection; Microsoft TechEd 2005 flair; app.config for mono; Getting ASP.NET working on Windows XP Tablet PC edition

posted at: 00:30 | path: /getopt | permanent link to this entry