DotNet-Arguments 2.0.0
A simple and 'to-the-point' library to parse launch arguments in .NET and .NET Core applications.
Loading...
Searching...
No Matches
.NET - Launch Arguments Parser Library

Nuget.org latest version Nuget.org downloads count Repository's License

A simple and 'to-the-point' library to parse launch arguments in .NET Framework 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.
It is also has the exact same features as the port in C99-Utility-Libraries.

Features

  • Easy to use, lightweight and 'to-the-point' philosophy
    • No unnecessary types, classes, procedures and whatnot
  • Support for 'git-like' verbs
  • Different behavior for options
    • Required options
    • Repeatable flag-like options
    • Multiple value
    • Multiple default option per verb with index-based ordering
    • Hidden in help text
    • Early parser exit
    • In-between verbs
  • Configurable help text printer
  • Easy exception filtering with inheritance
    • 1 common parent
    • 3 child for distinct parts of the library
    • 14 final errors thrown in specific places.
  • Supports modern developer QoL

Requirements

  • .NET Framework 3.5, 4.0 or newer
  • .NET Core 8.0 or newer

Documentation

Go to aziascreations.github.io/DotNet-Arguments/ for the HTML documentation.

Building

Please refer to the building.md file for more information.

Basic Example

The following example shows you how to declare 2 options and how to parse and use the launch arguments.

// 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(ArgumentsException) {
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 !");
}
OptionFlags
Binary enum that contains all the flags an Option can use. These flags can toggle some special behav...
Definition: OptionFlags.cs:13
Static class that contains a function related to parsing launch arguments.
Definition: ArgumentsParser.cs:10
static Verb ParseArguments(Verb rootVerb, string[] arguments)
Parses the given arguments into the given root Verb.
Definition: ArgumentsParser.cs:60
Static class that contains helpers related to printing a help text.
Definition: HelpText.cs:15
static string GetFullHelpText(Verb verb, string programName, uint consoleWidth=80, uint leftSpace=2, uint innerSpace=2, bool addVerbs=true)
Retrieves the complete help text with the usage and verb/options info and description.
Definition: HelpText.cs:426
Class Option models an option linked to one or more Verb that can be given in launch arguments to pas...
Definition: Option.cs:14
int Occurrences
Counter used to indicate how many times the Option was used during the parsing process.
Definition: Option.cs:55
bool WasUsed()
Checks if the Option was used in the parsed launch arguments.
Definition: Option.cs:164
Class Verb models a verb that can be given in launch arguments to select a specific action or subset ...
Definition: Verb.cs:14
Verb RegisterOption(Option option)
Attempts to register an Option in the current Verb.
Definition: Verb.cs:131
void Clear()
Clears any field and registered member's fields that may be modified once the launch arguments are pa...
Definition: Verb.cs:336

Other Examples

  • Regular Declaration
    • Standard recommended method of declaring and using the options and verbs
  • Loose Declaration
    • Declaration, registration and parsing done in a single nested statement
  • Help Text Printing
    • Showcases the behaviour of different option types, and how to properly print a help text
  • Basic Verb Usage
    • Simple verb usage, recursive help option, and normal processing

License

The code in this repository is licensed under CC0 1.0 Universal (CC0 1.0) (Public Domain).

The doxygen-awesome-css repository is used as a submodule for Doxygen and is licensed under the MIT license.