DotNetCore.CmdArgParser
Simple library capable of parsing out command line arguments. Very easy to use api and examples provided
Install / Use
/learn @PeterKottas/DotNetCore.CmdArgParserREADME
DotNetCore.CmdArgParser
Very easy to use and feature rich command line argument parser.
Installation
Using nuget: Install-Package PeterKottas.DotNetCore.CmdArgParser
Usage
- Using statement:
using PeterKottas.DotNetCore.CmdArgParser;
- Api for parsing:
CmdArgParser.Parse(config =>{
});
- 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
}
});
});
- 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;
}
}
});
});
- 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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
License
MIT
