ArgumentParsing 0.1.0

dotnet add package ArgumentParsing --version 0.1.0                
NuGet\Install-Package ArgumentParsing -Version 0.1.0                
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="ArgumentParsing" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ArgumentParsing --version 0.1.0                
#r "nuget: ArgumentParsing, 0.1.0"                
#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.
// Install ArgumentParsing as a Cake Addin
#addin nuget:?package=ArgumentParsing&version=0.1.0

// Install ArgumentParsing as a Cake Tool
#tool nuget:?package=ArgumentParsing&version=0.1.0                

Argument Parsing

Library for command line arguments parsing with intuitive API in declarative style, allowing you to build complex command line applications by simply declaring options type and annotating its members with attributes to get the desired behavior. All logic is source-generated, making this library completely AOT-friendly!

Overview

  • Best works on latest .NET version, but is .NET Standard 2.0 compatible, meaning it works on a huge variety of .NET versions, including .NET Framework
  • Provides simple declarative API: you define what you want and the library figures out how to achieve that
  • Supports wide variety of types, including nullable value types and immutable sequences like ImmutableArray<T>
  • Good integration with modern C# features (e.g. you can specify a required option/parameter by making its corresponding property required)
  • Provides default implementations of --help and --version commands with additional customization
  • All parsing logic is entirely source-generated, making this library completely NativeAOT-friendly
  • Delivers rich developer experience: the editor provides real-time diagnostics, including error detection, code suggestions and more as you type
  • Includes detailed and comprehensive wiki documentation

Quick start example

using ArgumentParsing;
using ArgumentParsing.Generated;
using ArgumentParsing.Results;
using ArgumentParsing.SpecialCommands.Help;
using System;
using System.Collections.Immutable;
using System.Linq;

namespace SimpleSumApp;

partial class Program
{
    private static void Main(string[] args)
    {
        ParseArguments(args).ExecuteDefaults(ExecuteMainApp);
    }

    [GeneratedArgumentParser]
    private static partial ParseResult<Options> ParseArguments(string[] args);

    private static void ExecuteMainApp(Options options)
    {
        // At this point all errors and special cases are handled, so we get valid options object we can work with
        var sum = options.FirstRequiredParameter + options.SecondRequiredParameter;
        if (options.Verbose)
        {
            Console.WriteLine($"Sum of 2 required parameters: {sum}");
        }

        var remainingSum = options.RemainingParameters.Sum();
        if (options.Verbose)
        {
            Console.WriteLine($"Sum of remaining parameters: {remainingSum}");
        }

        Console.WriteLine($"Total sum: {sum + remainingSum}");
    }
}

class Options
{
    [Option('v'), HelpInfo("Enables verbose logging")]
    public bool Verbose { get; init; }

    [Parameter(0)]
    public required int FirstRequiredParameter { get; init; }

    [Parameter(1)]
    public required int SecondRequiredParameter { get; init; }

    [RemainingParameters]
    public ImmutableArray<int> RemainingParameters { get; init; }
}
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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.0 1 3/3/2024