DotNet-Arguments View on GitHub
Introduction
A simple and 'to-the-point' library to parse launch arguments in .NET and .NET Core applications.
This library is an improved port of my PB-Arguments library that intended to achieve the same goals but was missing support for some features.
Requirements
● .NET v6.0+
● C# 10.0
Documentation
Go to "aziascreations.github.io/DotNet-Arguments/" for the HTML documentation.
Basic Example
// Preparing options and root verb.
Option OptionHelp = new('h', "help", "", OptionFlags.StopsParsing);
Option OptionVerbose = new('v', "verbose", "", OptionFlags.Repeatable);
Verb RootVerb = new Verb("").RegisterOption(OptionHelp).RegisterOption(OptionVerbose);
// Parsing lanch arguments
try {
ArgumentsParser.ParseArguments(RootVerb, args); // 'args' is gotten from Main().
} catch(ArgumentException) {
Console.Error.Write("Failed to parse the launch arguments !");
RootVerb.Clear(); // Ignoring the error and simulating no launch parameters.
}
// Using the results
if(OptionHelp.WasUsed()) {
Console.WriteLine(HelpText.GetFullHelpText(RootVerb, "app.exe"));
}
if(OptionVerbose.WasUsed() && OptionVerbose.Occurrences >= 2) {
// We count the number of occurences to enable more logging.
Console.WriteLine("Activating super-verbose mode !");
}
Option OptionHelp = new('h', "help", "", OptionFlags.StopsParsing);
Option OptionVerbose = new('v', "verbose", "", OptionFlags.Repeatable);
Verb RootVerb = new Verb("").RegisterOption(OptionHelp).RegisterOption(OptionVerbose);
// Parsing lanch arguments
try {
ArgumentsParser.ParseArguments(RootVerb, args); // 'args' is gotten from Main().
} catch(ArgumentException) {
Console.Error.Write("Failed to parse the launch arguments !");
RootVerb.Clear(); // Ignoring the error and simulating no launch parameters.
}
// Using the results
if(OptionHelp.WasUsed()) {
Console.WriteLine(HelpText.GetFullHelpText(RootVerb, "app.exe"));
}
if(OptionVerbose.WasUsed() && OptionVerbose.Occurrences >= 2) {
// We count the number of occurences to enable more logging.
Console.WriteLine("Activating super-verbose mode !");
}
CopyCopied
License
MIT License