Skip to content

Simple.ArgumentParser is a lightweight yet powerful and dynamic .NET command-line argument parser library that makes parsing arguments a breeze.

License

Notifications You must be signed in to change notification settings

henkla/Simple.ArgumentParser

Repository files navigation

Simple.ArgumentParser

A lightweight yet powerful and dynamic .NET command-line argument parser library that makes parsing arguments a breeze.

GitHub Repo stars GitHub search hit counter GitHub Actions Workflow Status GitHub Issues or Pull Requests NuGet version (Simple.ArgumentParser) NuGet Downloads


📑 Table of Contents

  1. 🚀 Quick Guide
  2. 🧠 Technical Information
  3. ⚠️ Known Issues & Limitations

✨ Key Features

  • Super quick and easy setup
  • Supports both short (-s) and long (--long) option styles
  • Built-in type validation for:
    • Alphanumeric
    • Integer
    • Boolean
    • Char
    • Double
    • Enumerated values (with custom allowed values)
    • Flags (value-less switches)
  • Automatically generated help section
  • Handles:
    • Required arguments
    • Invalid/ignored arguments
    • Missing arguments
  • Support for default values (coming soon)
  • Customizable prefixes (coming soon)

⚙️ Quick Guide

🔧 Basic Setup

var arguments = new ArgumentParser()
    .AddAlphaOption("alpha", 'a', "An alphanumeric option")
    .AddIntegerOption("integer", 'i', "An integer option")
    .AddBooleanOption("boolean", 'b', "A boolean option")
    .AddCharOption("char", 'c', "A char option")
    .AddDoubleOption("double", 'd', "A double option")
    .AddEnumerateOption("enumerate", 'e', "An enumerate option", ["accepted-value-1", "accepted-value-2"])
    .AddFlagOption("flag", 'f', "A flag option")
    .AddHelpOption("A description of the application.")
    .AddVersionOption("1.2.3-alpha")
    .Parse(args);

📦 Usage

📘 Dynamic Help

$ Simple.ArgumentParser.Example.exe --help

Prints a clear and comprehensive help section with descriptions.

✅ Valid Arguments

if (arguments.IsValid && arguments.Any())
{
    Console.WriteLine("Valid commands:");
    arguments.GetAll().ForEach(c =>
        Console.WriteLine($"Name: {c.Name}, Type: {c.OptionType}, Value: {c.Value}"));
}

❓ Help or Version Requests

if (arguments.HelpRequested)
{
    Console.WriteLine(arguments.HelpSection);
    return;
}

if (arguments.VersionRequested)
{
    Console.WriteLine(arguments.Version);
    return;
}

❌ Invalid Arguments

if (arguments.HasInvalidCommands)
{
    arguments.Invalid.ForEach(Console.WriteLine);
    return;
}

🚫 Missing Required Arguments

if (arguments.HasMissingCommands)
{
    arguments.Missing.ForEach(Console.WriteLine);
    return;
}

⚠️ Ignored Arguments

if (arguments.HasIgnoredCommands)
{
    Console.WriteLine("Ignored commands:");
    arguments.Ignored.ForEach(c =>
        Console.WriteLine($"Name: {c.Name}, Type: {c.OptionType}, Value: {c.Value}"));
}

🔍 Get Specific Argument

var specificCommand = arguments.Get("alpha");
Console.WriteLine($"Name: {specificCommand.Name}, Type: {specificCommand.OptionType}, Value: {specificCommand.Value}");

🧠 Technical Information

Coming soon.


⚠️ Known Issues & Limitations

  • No handling of conflicting argument names ✅ Resolved
  • Short names currently required — should be optional
  • Only -- and - prefixes are supported — prefix customization not yet available

That's it – Simple.ArgumentParser is ready to make your CLI apps cleaner and easier to maintain!

About

Simple.ArgumentParser is a lightweight yet powerful and dynamic .NET command-line argument parser library that makes parsing arguments a breeze.

Topics

Resources

License

Stars

Watchers

Forks

Languages