MiniCommandLineParser 1.0.3.1

dotnet add package MiniCommandLineParser --version 1.0.3.1
                    
NuGet\Install-Package MiniCommandLineParser -Version 1.0.3.1
                    
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="MiniCommandLineParser" Version="1.0.3.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiniCommandLineParser" Version="1.0.3.1" />
                    
Directory.Packages.props
<PackageReference Include="MiniCommandLineParser" />
                    
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 MiniCommandLineParser --version 1.0.3.1
                    
#r "nuget: MiniCommandLineParser, 1.0.3.1"
                    
#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 MiniCommandLineParser@1.0.3.1
                    
#: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=MiniCommandLineParser&version=1.0.3.1
                    
Install as a Cake Addin
#tool nuget:?package=MiniCommandLineParser&version=1.0.3.1
                    
Install as a Cake Tool

MiniCommandLineParser

A simple, lightweight, and dependency-free command-line parsing library for .NET.

âœĻ Features

  • ðŸŠķ Lightweight - Minimal footprint, no external dependencies
  • ðŸŽŊ Simple API - Intuitive attribute-based configuration
  • ðŸ“Ķ Multi-target - Supports .NET 6/7/8/9 and .NET Standard 2.1
  • 🔄 Bidirectional - Parse arguments to objects AND format objects back to command-line strings
  • 📝 Auto Help Text - Built-in help text generation with default value display
  • 🔧 Flexible - Supports short/long options, arrays, enums, flags, and more
  • 📍 Positional Arguments - Support index-based positional parameters (e.g., app clone http://...)
  • ✂ïļ Custom Separators - Split array values with custom separators (e.g., --tags=a;b;c)
  • 🌍 Environment Variables - Fallback to environment variables when options not provided
  • ⚠ïļ Structured Errors - Typed error handling with ParseError and ParseErrorType
  • ⚡ High Performance - Thread-safe TypeInfo caching for efficient parsing

ðŸ“Ĩ Installation

dotnet add package MiniCommandLineParser

🚀 Quick Start

1. Define Your Options Class

using MiniCommandLineParser;

public class Options
{
    [Option('i', "input", Required = true, HelpText = "Input file path")]
    public string InputFile { get; set; }

    [Option('o', "output", HelpText = "Output file path")]
    public string OutputFile { get; set; }

    [Option('v', "verbose", HelpText = "Enable verbose output")]
    public bool Verbose { get; set; }

    [Option("count", HelpText = "Number of iterations")]
    public int Count { get; set; } = 1;

    [Option("tags", HelpText = "List of tags")]
    public List<string> Tags { get; set; }
}

2. Parse Command-Line Arguments

var result = Parser.Default.Parse<Options>(args);

if (result.Result == ParserResultType.Parsed)
{
    var options = result.Value;
    Console.WriteLine($"Input: {options.InputFile}");
}
else
{
    Console.WriteLine(result.ErrorMessage);
    
    // Access structured errors
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"[{error.ErrorType}] {error.OptionName}: {error.Message}");
    }
}

🌍 Environment Variable Support

Fallback to environment variables when command-line options are not provided:

public class Options
{
    [Option('c', "config", EnvironmentVariable = "APP_CONFIG", HelpText = "Config file path")]
    public string ConfigFile { get; set; }

    [Option("api-key", EnvironmentVariable = "API_KEY", HelpText = "API key for authentication")]
    public string ApiKey { get; set; }

    [Option("timeout", EnvironmentVariable = "APP_TIMEOUT", HelpText = "Timeout in seconds")]
    public int Timeout { get; set; } = 30;
}

// Command line takes precedence over environment variables
// If --config is not provided, APP_CONFIG environment variable is used
// If neither is set, property keeps its default value

Priority order: Command-line argument > Environment variable > Default value

📍 Positional Arguments

Support CLI-style positional parameters without option names:

public class CloneOptions
{
    [Option("command", Index = 0, HelpText = "Command name")]
    public string Command { get; set; }

    [Option("url", Index = 1, HelpText = "Repository URL")]
    public string Url { get; set; }

    [Option('v', "verbose", HelpText = "Verbose output")]
    public bool Verbose { get; set; }
}

// Parse: myapp clone https://github.com/user/repo --verbose
// Result: Command="clone", Url="https://github.com/user/repo", Verbose=true

✂ïļ Custom Array Separators

Split array values using custom separators:

public class BuildOptions
{
    // Default separator is ';'
    [Option("tags", Separator = ';', HelpText = "Tags separated by semicolon")]
    public List<string> Tags { get; set; }

    // Custom separator
    [Option("ids", Separator = ',', HelpText = "IDs separated by comma")]
    public int[] Ids { get; set; }
}

// Parse: --tags=dev;test;prod --ids=1,2,3
// Result: Tags=["dev","test","prod"], Ids=[1,2,3]

⚠ïļ Structured Error Handling

Access detailed error information with typed errors:

var result = Parser.Default.Parse<Options>(args);

if (result.Result == ParserResultType.NotParsed)
{
    foreach (var error in result.Errors)
    {
        switch (error.ErrorType)
        {
            case ParseErrorType.MissingRequired:
                Console.WriteLine($"Missing required option: {error.OptionName}");
                break;
            case ParseErrorType.InvalidValue:
                Console.WriteLine($"Invalid value for {error.OptionName}: {error.Message}");
                break;
            case ParseErrorType.UnknownOption:
                Console.WriteLine($"Unknown option: {error.OptionName}");
                break;
        }
    }
}

Error Types: | Type | Description | |------|-------------| | MissingRequired | A required option was not provided | | InvalidValue | The value could not be converted to the expected type | | UnknownOption | An unrecognized option was provided |

📖 Supported Argument Formats

# Short options
-v -i input.txt

# Long options
--verbose --input input.txt

# Equals syntax
--input=input.txt --config="key=value"

# Boolean options (all equivalent)
--verbose
--verbose=true
--verbose true

# Quoted values (with spaces)
--output "my output file.txt"

# Array values (space-separated)
--tags tag1 tag2 tag3

# Array values (with separator)
--tags=tag1;tag2;tag3

# Positional arguments
clone https://example.com --verbose

# Flags enum
--flags Flag1 Flag2 Flag3

🔄 Format Object to Command Line

Convert objects back to command-line strings with flexible formatting options:

var options = new Options { InputFile = "test.txt", Verbose = true };

// Full output (all options with space syntax)
string cmdLine = Parser.FormatCommandLine(options, CommandLineFormatMethod.Complete);
// Output: --input test.txt --verbose True --count 1

// Simplified output (only non-default values)
string simplified = Parser.FormatCommandLine(options, CommandLineFormatMethod.Simplify);
// Output: --input test.txt --verbose True

// Equal sign style (use = between option and value)
string equalStyle = Parser.FormatCommandLine(options, CommandLineFormatMethod.EqualSignStyle);
// Output: --input=test.txt --verbose=True --count=1

// Combine flags: Simplify + EqualSignStyle
string combined = Parser.FormatCommandLine(options, 
    CommandLineFormatMethod.Simplify | CommandLineFormatMethod.EqualSignStyle);
// Output: --input=test.txt --verbose=True

Format Method Flags

Flag Description
None Default space-separated style
Complete Output all options including defaults
Simplify Only output non-default values
EqualSignStyle Use --option=value syntax, arrays use separator

📝 Auto-Generate Help Text

var helpText = Parser.GetHelpText(new Options());
Console.WriteLine(helpText);

Help text automatically shows:

  • Option names (short and long)
  • Required/Optional status
  • Default values
  • Environment variable names
  • Type information (Array, Enum, Flags)

⚙ïļ Parser Settings

var parser = new Parser(new ParserSettings
{
    CaseSensitive = false,          // Case-insensitive matching (default)
    IgnoreUnknownArguments = true   // Ignore unknown arguments (default)
});

⚡ Performance

  • TypeInfo Caching: Type metadata is cached and reused across parse calls
  • Thread-Safe: Safe for concurrent usage in multi-threaded applications
  • Minimal Allocations: Optimized for low memory overhead
// TypeInfo is cached - subsequent calls are fast
var typeInfo = Parser.GetTypeInfo<Options>();

📄 License

MIT License - see GitHub Repository for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • 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.0.3.1 0 2/6/2026
1.0.2.2 82 1/30/2026
1.0.2.1 84 1/28/2026
1.0.1.1 83 1/22/2026
1.0.0.1 88 1/20/2026