HappyCLI 1.0.0

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

HappyCLI

NuGet Version .NET Support License

Provides a simple reflection based service setup for creating a cli. Useful for creating internal tools.

Installation

dotnet add package HappyCLI

How to create a command

First create a class to represent the options for a given cli command...

public class ExampleOptions
{
    public string Str { get; set; }
    public int Int { get; set; }
    public List<string> StrCol { get; set; }
    public List<int> IntCol { get; set; }
    public bool Bool { get; set; }
}

Then implement ICommandHandler<ExampleOptions>...

public class ExampleCommand : ICommandHandler<ExampleOptions>
{
    public string CommandName { get; } = "C1";
    public string CommandDescription { get; } = "An example of a command";
	
    public OptionsConfiguration<ExampleOptions> OptionsConfiguration { get; } = new OptionsConfigurationBuilder<ExampleOptions>()
        .Add("s", "Str").ForString(x => x.Str)
        .Add("i", "Int").ForInt(x => x.Int)
        .Add("sc", "Str Col").ForStringCollection(x => x.StrCol, true)
        .Add("ic", "Int Col").ForIntCollection(x => x.IntCol)
        .Add("b", "Bool").ForBool(x => x.Bool)
        .Build();
		
    public Task ExecuteCommand(ExampleOptions options)
    {
        Console.WriteLine(options.Str);
        Console.WriteLine(options.Int);

        foreach (var str in options.StrCol)
            Console.WriteLine(str);

        foreach (var i in options.IntCol)
            Console.WriteLine(i);

        Console.WriteLine(options.Bool);
        return Task.CompletedTask;
    }
}

But what does all this mean?

The CommandName property is the first argument that you will pass to your console app to instruct it that you want to execute ExampleCommand.

The CommandDescription property is useful when you ask for help (more on this later).

The ExecuteCommand method is the method that will be executed by BaseCLI.

OptionsConfiguration

It's important to be able to pass options to your commands and as you can see BaseCLI provides a useful builder interface to help set these up. There are five types of options currently supported which are string, int, List<string>, List<int> and bool and it is also possible to make options mandatory.

You pass a string in your console like so... -flag "test string"

You pass a int in your console like so... -flag 1

You pass a List<string> in your console like so... -flag hello -flag world

You pass a List<int> in your console like so... -flag 10 -flag 20

You pass a bool in your console like so... -flag

How to setup your commands?

Simply call the following code from you console...

    internal class Program
    {
        static void Main(string[] args)
        {
            CLI.Execute(args, new[] { typeof(ExampleOptions).Assembly }, services => { });
        }
    }

As you can see you simply pass the raw command-line args from the main method as well as the assemblies containing your commands, optionally you can wire up your own services too.

How to execute your commands?

executing .\TestConsole.exe C1 -s "Test String" -i 1 -sc Hello -sc World -ic 10 -ic 20 -b from the command line using the example above will result in the following output...

Test String
1
Hello
World
10
20
True

Getting help

After you've made your extremely useful cli tool you'll probably forget how to use all the commands you created, don't worry you can easily ask for help.

executing .\TestConsole.exe -h will output a list of your commands and their descriptions

C1 - An example of a command
C2 - Another example of a command

and executing .\TestConsole.exe C1 -h will output information about command "C1"

C1 - An example of a command
-s Str - A string
-i Int - An integer
-sc Str Col (mandatory) - A collection of strings
-ic Int Col - A collection of integers
-b Bool - A boolean
Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.0.0 41 5/17/2026

Initial release of HappyCLI. Supports string, int, bool, and collection option types with built-in help output and mandatory option enforcement. See CHANGELOG.md for full details.