Cliffer

I write a lot of little command-line tools, and every time I did, I found myself writing the same boilerplate again: parse the arguments, wire up the commands, print the help, hook up configuration and services. Microsoft's System.CommandLine handles the parsing well, but I still had to do a lot of plumbing around it. Cliffer is my answer to that. You write the business logic you need, declare your intentions with a few attributes, and Cliffer takes care of the rest.

How it works

A command in Cliffer is a class with an [Command] attribute and an Execute method. Its arguments and options are declared with attributes too. When the command runs, Cliffer passes the arguments to Execute as parameters, along with any services the method asks for, taken from the standard .NET dependency-injection container. You set it all up with a builder:

var cli = new ClifferBuilder()
    .ConfigureServices(services => { /* your services */ })
    .Build();

On top of that, you get:

  • help text generated from your declarations;
  • a built-in REPL, so your program can run as an interactive prompt as well as a one-shot command;
  • macros, defined in configuration or in code, that expand into longer commands;
  • configuration read from JSON in the usual .NET way.

Demos

The best way to see what it can do is to look at what I've built with it. Cliffer Basic is an old-school BASIC interpreter that runs entirely on Cliffer's REPL, and Clic is a stack-based calculator. Some of the demos are in various stages of being built, like the library itself.

Details

  • Written in C# for .NET 8, on System.CommandLine.
  • Available on NuGet as a prerelease: dotnet add package Cliffer --prerelease
  • Licensed under MIT.

The code is on GitHub: github.com/paulmooreparks/Cliffer, and the package is at nuget.org/packages/Cliffer.