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: dotnet c# opensource]

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

    Add a comment to this post:

    Your name:

    Your email: Email me new comments on this post
      (Your email will not be published on this site, and will only be used to contact you directly with a reply to your comment if needed. Oh, and we'll use it to send you new comments on this post it you selected that checkbox.)


    Your website:

    Comments: