.NET Command Line Library
Microsoft develops and maintains multiple CLI tools, like dotnet
and winget
. They are working on migrating the System.CommandLine
library into .NET 9.
I regularly create command line tools in dotnet, when Nushell shell scripting is not enough. Yesterday I created a utility for editing file metadata (specifically file created, write, and access time stamps).
I found System.CommandLine which offers command line integration with multiple supportive features.
The project also publishes dotnet-suggest
which supposedly generalizes and eases shell auto-completion integration.
The library is in preview, and the efforts towards .NET 9 are currently in a feature branch. It was still very much usable.
In the end I did switch to Spectre.Console, which is mentioned in the official dotnet/System.CommandLine documentation.
Their approach is a little bit different in that you create a class hierarchy for commands and arguments instead of using a fluent API.
Spectre natively supports colors, some prompts, selection menus, widgets, and layouts.
In both I was missing line-editors (that go beyond input). Spectre is extensible though, so I will likely create one at some point.