Wiki

Clone wiki

SimpleCmdLine / Home

Welcome

Simple command line library for .NET console applications which follows convention over configuration. Here are the conventions: * Options start with "--" for long option or "-" for short option * If "--help" or "-h" is specified then help is shown * If a required option is missing then an exception is thrown * Non required options will have default(T) value

Example 1:

#!c#
var cmdLine = new CmdLineParser();
cmdLine.Setup<string>("xstring");
cmdLine.Parse(new[]{"--xstring", "abc"});

// now you can use cmdLine.Opts.xstring
Example 2:
#!c#
var cmdLine = new CmdLineParser();
cmdLine.Setup<string>("xstring", true, "help message");
cmdLine.Parse(new[]{"-h"});
// will throw CmdLineParseException
//  print out the HelpMessage of the exception
Example 3:
#!c#
var cmdLine = new CmdLineParser();
cmdLine.Setup<int>("xint,i", false);
//following are valid cmd lines
cmdLine.Parse(new[]{}); //cmdLine.Opts.xint has value of 0
cmdLine.Parse(new[]{"--xint","3"});
cmdLine.Parse{new[]{"-i","3"});

Example 4:

#!c#
var cmdLine = new CmdLineParser();
cmdLine.Setup<int[]>("option");

cmdLine.Parse{new[]{"--option","1,2,3,4,5"});

cmdLine.Opts.option[0] //1
Check the tests for more usage and non-usage:)

Future: 1. Support windows style options '/' 2. Configuration options via the constructor 3. verb-style options

Updated