Command Line Parser Library allows CLR applications to define a syntax for parsing command line arguments. It is very easy to incorporate this library into your C# project.
To install Command Line Parser Library, run the following command in the Package Manager Console:
PM> Install-Package CommandLineParser
Create a new class called CmdOptions, where the command line arguments are model with class properties:
To consume the command line argument:
static void Main(string[] args)
{
CmdOptions ops=new CmdOptions();
bool bSuccess = CommandLine.Parser.Default.ParseArguments(args, ops);
if (bSuccess)
Console.WriteLine(ops.InputPhrase, ops.FontName);
else
Console.Write(CmdOptions.HelpInfo); //output help strings
}
Running this app with no argument, and the result shows the help string in CmdOptions class:
So simple to use! Enjoy~
Filed under: Dotnet/C#, Programming Tagged: C#, cmd, command line argument, Command Line Parser Library, example, hyphen argument, parsing
