HatTrick.CommandLine 2.5.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package HatTrick.CommandLine --version 2.5.0
                    
NuGet\Install-Package HatTrick.CommandLine -Version 2.5.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="HatTrick.CommandLine" Version="2.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HatTrick.CommandLine" Version="2.5.0" />
                    
Directory.Packages.props
<PackageReference Include="HatTrick.CommandLine" />
                    
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 HatTrick.CommandLine --version 2.5.0
                    
#r "nuget: HatTrick.CommandLine, 2.5.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.
#:package HatTrick.CommandLine@2.5.0
                    
#: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=HatTrick.CommandLine&version=2.5.0
                    
Install as a Cake Addin
#tool nuget:?package=HatTrick.CommandLine&version=2.5.0
                    
Install as a Cake Tool

HatTrick.CommandLine

NuGet License: Apache-2.0

Argument parsing, type conversion, constraint validation, and handler dispatch for building structured, validated .NET 9 CLI applications.

Full documentation | hattricklabs.com


Installation

dotnet add package HatTrick.CommandLine

Quick Start

var registry = DefinitionRegistry.GetInstance();

registry.Add(new NamespaceDefinition("htl", "HatTrick Labs namespace"));

var cmdDef = new CommandDefinition("htl.guid");
cmdDef.Help = "Generates one or many GUID values.";

cmdDef.AddOption<string>(key: "format", defaultArg: "D", help: "GUID format specifier.", (terse: "-f", verbose: "--format"));
cmdDef["format"].AcceptedValues("N", "D", "B", "P", "X");

cmdDef.AddOption<int>(key: "count", defaultArg: 1, help: "Number of GUIDs to generate.", (terse: "-c", verbose: "--count"));
cmdDef["count"].ApplyConstraint<int>(cnt => cnt > 0 && cnt <= 100, "Allowed Range", "1..100.");

cmdDef.Handler = (cmd) =>
{
    int count = cmd["count"].GetValue<int>();
    string format = cmd["format"].GetValue<string>();
    for (int i = 0; i < count; i++)
        Console.WriteLine(Guid.NewGuid().ToString(format));
};

registry.Add(cmdDef);

Command cmd = CommandBuilder.Build(args);
CommandExecutor executor = registry.GetCommandExecutor(cmd);
executor.Execute();

Features

  • Namespaces and commands, with naming-collision validation at registration
  • Options and flags — positional arguments, boolean flags, terse flag chaining
  • Type conversion for built-in and custom types, including nint/nuint
  • Option-level and command-level constraints, including mutually-exclusive sets
  • Handlers, pre-execution hooks, and a default-command/help/version pipeline
  • Masked input for interactive prompts
  • MapTo<T> / MapToSignature<T> to map parsed options directly to POCOs or method calls
  • A typed exception model (CommandDefinitionException, CommandInputException, CommandParseException, OptionArgumentException, CommandExecutionException)

See the full documentation for all of the above in depth.


License

Apache-2.0 — see LICENSE.

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.

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
2.6.0 92 7/27/2026
2.5.0 108 6/20/2026

Initial public release. Versioned and used internally since 2023 — this release continues that version history rather than resetting to 1.0.