Skip to content

💻 A simple, light-weight and strongly typed Command Line Parser made in .NET Standard!

License

Notifications You must be signed in to change notification settings

MatthiWare/CommandLineParser.Core

Folders and files

NameName
Last commit message
Last commit date
Jun 23, 2022
Oct 31, 2022
Oct 31, 2022
Oct 31, 2022
Oct 31, 2022
Sep 20, 2020
Sep 12, 2018
Sep 27, 2020
Mar 1, 2022
Mar 1, 2022
Jan 9, 2021
Dec 28, 2018

Repository files navigation

.NET Core Issues CodeCov CodeFactor License Nuget

CommandLineParser

A simple, light-weight and strongly typed commandline parser made in .NET Standard!

Installation

PM> Install-Package MatthiWare.CommandLineParser

Quick Start

Example of configuring the port option using the Fluent API.

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 parserResult = parser.Parse(args);

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

      return -1;
   }

   var serverOptions = parserResult.Result;

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

private class ServerOptions
{
   // options
   public int Port { get; set; }
}

Run command line

dotnet myapp --port 2551

For more advanced configuration options see the wiki.

Contributors