Commandment 2.0.0-beta1

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

<div align="center"> <img width="384" src="./res/commandment.png" />

<br>

Commandment

Let there be a good command-line interface

</div>

<br>

Commandment provides fluent builder extension methods for the new System.CommandLine API

Add to your project

$> dotnet add package Commandment --prerelease

Build a fluent and composable CLI

Program.cs

using System.CommandLine;
using Commandment;

// Create build a typed argument ...
var fooOpt = new Option<uint>("--foo", "-f")
  .WithDescription("Foo")
  .NonZero() // ... with convenient numeric validation methods
  .Required();

// Create an option that takes a variant of `MyEnum` ...
var barOpt = new Option<string>("--bar", "-b")
  .WithDescription("Bar")
  .ValidEnumVariant<MyEnum>(ignoreCase: true, showVariantsOnError: true) // ... with configurable parsing and validation
  .Optional()
  .ZeroOrOneArg()
  .WithDefaultValue(MyEnum.Baz.ToString());

// Create an option that takes a string ...
var bazOpt = new Option<string>("--baz", "-B")
  .WithDescription("Baz")
  .ValidFilePath() // ... with file/directory path validation
  .Required(true);

// Put it all together
new RootCommand("My first Commandment-based CLI")
  .AddOption(fooOpt)
  .AddOption(barOpt)
  .AddOption(bazOpt)
  .WithAsyncAction(async (result, cancelToken) => {
    Console.WriteLine($"--foo='{result.GetValue(fooOpt)}'");
    Console.WriteLine($"--bar='{result.GetValue(barOpt)}'");
    Console.WriteLine($"--baz='{result.GetValue(bazOpt)}'");

    await Task.CompletedTask;

    return 0;
  })
  .Parse(["--foo=42", "--bar=Foo", "-BProgram.cs"])
  .Invoke();

enum MyEnum {
  Foo,
  Bar,
  Baz
}

Output:

--foo='42'
--bar='Foo'
--baz='Program.cs'

<br>


Future plans:

  • Implement fluent extensions
  • Create tests
  • Create a reflection-based declarative builder API
    • Define attribute API for Command, Subcommand, and Option
    • Implement reflection-based builder
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.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.

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.0.0-beta1 197 8/7/2025
2.0.0-beta 362 8/6/2025 2.0.0-beta is deprecated because it has critical bugs.