Majo.Command 0.0.1

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

Majo.Command

A lightweight, typed command-tree library for .NET.

Majo.Command provides declarative command registration, positional argument parsing, asynchronous execution, and help generation. A single command tree can serve commands from console applications, chat services, and other input sources.

Installation

dotnet add package Majo.Command

Target framework: .NET 10.

Features

  • Fluent registration of command keywords and typed positional arguments
  • Case-insensitive literal matching
  • Built-in and custom argument parsers, with optional regex validation
  • Quoted arguments and trailing free-text arguments
  • Asynchronous handlers with cancellation-token support
  • Execution contexts with customizable output callbacks
  • Typed argument access and structured matching results
  • Automatic help generation with optional-argument notation
  • Frozen command trees reusable across independent requests

Quick Start

using Majo.Command;

var builder = new CommandTreeBuilder<CommandContext>();

builder.Literal("say", say =>
{
    say.Argument("message", message =>
    {
        message.Executes(PrintAsync, "Prints a message.");
        message.Argument("tag", tag => tag.Executes(PrintAsync));
    });
});

var tree = builder.Build();
var context = new CommandContext((level, text, tag) => Console.WriteLine($"[{level}] [{tag}] {text}"));

var result = await tree.ExecuteAsync("say \"Hello world\" Greeting", context);
if (!result.Success)
    Console.Error.WriteLine(result.ErrorMessage);

Console.WriteLine(tree.GetHelp("say"));

static Task PrintAsync(CommandInvocation<CommandContext> call, CancellationToken ct)
{
    string message = call.Get<string>("message");
    string tag = call.TryGet<string>("tag", out var suppliedTag) ? suppliedTag : "Command";
    call.Context.Output(OutputLevel.Information, message, tag);
    return Task.CompletedTask;
}

The generated help entry is:

say <message> [tag] - Prints a message.

Command Registration

Use Literal(...) for command keywords and Argument(...) for string parameters. Argument<T>(...) parses values implementing ISpanParsable<T> with invariant culture.

For specialized formats, use CommandValueParser<T> or supply a Regex when registering a string argument. Set consumeRemaining: true on a final argument to capture the rest of the input.

Register Executes(...) at each point where a command can finish. This also lets help display consecutive trailing arguments in brackets, such as [tag].

Matching and Help

  • tree.Match(input) returns matching status and parsed argument values.
  • tree.ExecuteAsync(input, context, ct) matches and executes the registered handler.
  • match.Success, match.Error, and match.ErrorMessage describe the matching result.
  • Get<T>(name) and TryGet<T>(name, out value) retrieve parsed arguments.
  • tree.GetHelp() lists executable commands; tree.GetHelp("say") filters by literal path.

Execution Context

CommandContext accepts an output callback receiving OutputLevel, message text, and tag. Connect the callback to your application's output destination, such as a logger or messaging service.

For additional request-specific data, derive a custom context from CommandContext and use it as the type parameter to CommandTreeBuilder<TContext>.

Build the tree once and reuse it across requests. Each command match has its own argument values and can be executed with a separate context.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
0.0.1 109 10/20/2026

Initial release.