kaiserthe13th /
sarge
A very simple argument parsing library in C
Loading repository data…
FFMG / repository
A very simple c# command line arguments Parser, include the nuget package, add to your program and you are done...

A very simple c# command line arguments Parser
Install-Package MyOddWeb.CommandlineParser
dotnet add package MyOddWeb.CommandlineParser
packet add MyOddWeb.CommandlineParser
Lets say that we have a application that has command line options to install and run as a console
using myoddweb.commandlineparser;
using myoddweb.commandlineparser.Rules;
private void Bar()
{
...
var arguments = new CommandlineParser(args, new CommandlineArgumentRules
{
new HelpCommandlineArgumentRule( new []{"help", "h"} ) },
new OptionalCommandlineArgumentRule( "config", "config.json" ),
new OptionalCommandlineArgumentRule( "install" ),
new OptionalCommandlineArgumentRule( "console" ),
new RequiredCommandlineArgumentRule( "name" )
});
...
}
We can then check if we are running as a console
...
if (arguments.IsSet("console"))
{
InvokeActionInstall();
return;
}
...
We can also call the config value as we know it exists... (we have a default value)
...
var config = _arguments["config"];
...
We can also get a default value directly
For example, in the example below, we will either get the number that was passed, (example.exe --a 32), or the default value.
The value itself will be an integer, as this is what we expect...
...
var theGalaxy = parser.Get<int>("a", 42)
...
The argument does not have to have a value, for example you could have example.exe --a --b
In that case you would simply default
...
var arguments = new CommandlineParser(args, null );
...
What if you want a different leading pattern ...? Something like example.exe -a -b
Simply pass it as a third argument ...
...
var arguments = new CommandlineParser(args, null, "-" );
...
Selected from shared topics, language and repository description—not editorial ratings.
kaiserthe13th /
A very simple argument parsing library in C
AlexDanyluik /
ArgParse is a simple c library which helps with command-line argument parsing. It is in a very initial phase and hence not meant for use in any type of project.