[Mono-list] C# command line parsing library

gsscoder zero.one.etc at gmail.com
Thu May 17 19:25:43 UTC 2012


Please give a look to my library.

Project Home: http://commandline.codeplex.com/
Source Repo: http://commandline.codeplex.com/

Reference it or add two .cs file to your project (/CommandLine.cs/ | parser
and /CommandLineText.cs/ | help builder).

Create a target class for receive parsed values (and handle help screen
printing):

class Options {
      *[Option("r", "read", Required=True, HelpText="Input file to be
processed.")]*
      public string InputFile { get; set; }

      *[Option("v", "verbose", HelpText="Output all messages to standard
output.")]*
      public bool Verbose { get; set; }

      *[HelpOption]*
      public string GetUsage() {
        var help = new *HelpText*(new HeadingInfo("git-sample", "0.1"));
        help.Copyright = new CopyrightInfo("mr the author", 2005, 2012);
        help.AddPreOptionsLine("some custom stuff here");
        help.AddOptions(this);
        return help;
      }
    }

then with one instruction you can parse command line arguments:

static void Main(string[] args) {
      var options = new Options();
      if (*CommandLineParser.Default.ParseArguments(args, options)*) {
        // Consume values here
        if (options.Verbose) Console.WriteLine("Filename: {0}",
options.InputFile);
      }
    }

Have fun!

Regards,
Giacomo

--
View this message in context: http://mono.1490590.n4.nabble.com/C-command-line-parsing-library-tp1502157p4643467.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list