/DotNetCore.CmdArgParser

Simple library capable of parsing out command line arguments. Very easy to use api and examples provided

Primary LanguageC#MIT LicenseMIT

DotNetCore.CmdArgParser

Very easy to use and feature rich command line argument parser.

Installation

Using nuget: Install-Package PeterKottas.DotNetCore.CmdArgParser

Usage

  1. Using statement:
using PeterKottas.DotNetCore.CmdArgParser;
  1. Api for parsing:
CmdArgParser.Parse(config =>{
});
  1. Add your first parsing parameter
CmdArgParser.Parse(config =>{
  config.AddParameter(new CmdArgParam()
    {
      Key = "1stParamKey",
      Description = "This description is used for help",
      Value = val =>
      {
        innerConfig.Username = val; //What happens when we find this key, callback with injected value
      }
  });
});
  1. Advanced example
CmdArgParser.Parse(config =>{
  config.AddParameter(new CmdArgParam()
    {
      Key = "1stParamKey",
      Description = "This description is used for help",
      Value = val =>
      {
        switch(val){
          case "a":
            break;
          case "b":
            break
          default:
            Console.WriteLine("Only \"a\" and \"b\" are allowed values for key \"1stParamKey\". {0} was provided instead." val);
            break;
        }
      }
  });
});
  1. Parser api
CmdArgParser.Parse(config =>{
  config.UseDefaultHelp();//Configures a "help" parameter which displays default help
  config.UseAppDescription();//Configures app description used in help
  config.ShowHelpOnExtraArguments();//Show's extra arguments
  config.CustomHelp(helpData=>
  {
  });//Configures custom help. You can provide a function that displays custom help for you application. You get the array of parameters provided to you via parameter HelpData
  config.DisplayHelp();//Displays help. Useful inside parameter callbacks.
});

Created and sponsored by

  • GuestBell - Customer centric online POS for Hotels and short terms stays.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT