EasyArguments 1.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyArguments --version 1.0.8
                    
NuGet\Install-Package EasyArguments -Version 1.0.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyArguments" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyArguments" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="EasyArguments" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyArguments --version 1.0.8
                    
#r "nuget: EasyArguments, 1.0.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EasyArguments@1.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyArguments&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=EasyArguments&version=1.0.8
                    
Install as a Cake Tool

<div align="center">

EasyArguments

GitHub NuGet download count NuGet Build

EasyArguments is a lightweight .NET library that simplifies the process of parsing command-line arguments into strongly-typed objects.

NugetPackageInstallation

</div>

Table of Contents

About the project

Parsing command-line arguments in .NET applications can often be cumbersome and error-prone, requiring repetitive code to handle different argument formats, validations, and help documentation. EasyArguments streamlines this process by providing a simple, declarative way to map command-line arguments to strongly-typed objects with minimal boilerplate code.

Key Features ✨

  • Attribute-Based Configuration: Define arguments using [Argument] attributes directly on your model properties.

  • Strongly-Typed Parsing: Automatically convert arguments to their correct data types (e.g., string, bool, int).

  • Boolean Flags and Inversion: Support for flags like --verbose and inverted options like --no-gui with the InvertBoolean parameter.

  • Automatic Help Generation: Built-in --help command generates a formatted help screen based on your argument definitions.

  • Automatic methods execution Automatically execute any static method that you want while parsing!

  • Validation: Mark arguments as required, and let the library handle missing or invalid inputs gracefully.

  • Lightweight: Minimal dependencies and low overhead, designed for performance and simplicity.

Why EasyArguments? 🚀

  • Reduce Boilerplate: Eliminate manual parsing loops and condition checks.

  • Intuitive Syntax: Declare arguments naturally with C# properties and attributes.

  • Flexible: Supports both short (-n) and long (--name) argument formats.

  • Error Handling: Clear exception messages guide users when inputs are missing or invalid.

Ideal for developers who want to build robust CLI tools, EasyArguments empowers you to define, parse, and validate arguments in minutes. Check out the Basic Usage Example to get started or explore the Full Documentation for advanced features!

Installation 👌

You can install EasyArguments via terminal:

dotnet add package EasyArguments

Or via nuget package manager on Visual Studio:

NugetPackageInstallation

Basic Usage Example 📝

This is a basic example. For a comprehensive guide, check out the Full Documentation 📚.

1) Setup an argument class

using EasyArguments;
using EasyArguments.Attributes;
using System;

// The 'Name' parameter specifies the name of the application or command,
// which will be displayed when the user invokes the --help option.
[ArgumentsController(Name = "you_app.exe")]
public class MyArgs
{
    [Argument("-n", "--name", "Specifies the user name", Required = true)]
    public string? Name { get; set; }

    [Argument("-v", "--verbose", "Enable verbose output", Required = false)]
    public bool? Verbose { get; set; }

    [Argument(null, "--no-gui", "Disable the GUI", InvertBoolean = true)]
    public bool GuiEnabled { get; set; }
}

2) Create an instance of ArgumentsController

using EasyArguments;

public class Program
{
    static void Main(string[] args)
    {
        try
        {
            // Instantiate a controller for your argument class
            var controller = new ArgumentsController<MyArgs>(args);

            // Parse the given args
            MyArgs parsed = controller.Parse();

            // Now you can use properties as you want:
            Console.WriteLine($"Name: {parsed.Name}");
            Console.WriteLine($"Verbose: {parsed.Verbose}");
            Console.WriteLine($"GUI enabled: {parsed.GuiEnabled}");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

Contribution ❤️

Contributions are welcome!
If you have ideas to improve EasyArguments feel free to open an issue.

License 🪪

This project is licensed under the GPLv3 License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 123 2/4/2025
1.0.8 110 2/2/2025
1.0.6 109 1/31/2025
1.0.4 100 1/28/2025
1.0.3 105 1/25/2025
1.0.2 105 1/25/2025
1.0.1 107 1/25/2025
1.0.0 108 1/25/2025