Skip to content

Quick Start

Matthias Beerens edited this page Dec 30, 2018 · 5 revisions

Quick Start

First of all you need to add the nuget package.

PM> Install-Package MatthiWare.CommandLineParser

Now you can setup the command line parser.

static void Main(string[] args)
{
   // create the parser
   var parser = new CommandLineParser<ServerOptions>();
   
   // configure the options using the fluent api
   parser.Configure(options => options.Port)
      .Name("p", "port")
      .Description("The port of the server")
      .Required();

   // parse
   var result = parser.Parse(args);

   // check for parsing errors
   if (result.HasErrors)
   {
      Console.ReadKey();

      return -1;
   }

   Console.WriteLine($"Parsed port is {result.Result.Port}");
}

Run command line

dotnet myapp --port 2551
Clone this wiki locally