UtilityCli 0.1.4-preview

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

UtilityCli

Quickly build utility applications that parse the command-line

UtilityCli is built for simple utility console application scenarios. As a wrapper around System.CommandLine, UtilityCli provides simple APIs for extracting strongly-typed options and arguments from the command line args. UtilityCli does not require the CLI to be defined/modeled up-front. Instead, the model is progressively defined while extracting the option and argument values.

// --org dotnet --repo runtime area-System.Security untriaged --dry-run --issue 40074 --pr 40075 --verbose --clear
// -o dotnet -r runtime area-System.Security untriaged --dry-run -i 40074 -p 40075 -vc

var cli = UtilityCli.CliArgs.Parse(args);

string org = cli.GetRequiredString("org", aliases: ["owner"]);
string repo = cli.GetRequiredString("repo");
bool clearExistingLabels = cli.HasFlag("clear");

int[] issues = cli.GetInt32s("issue") ?? [];
int[] prs = cli.GetInt32s("pr") ?? [];

bool verboseOutput = cli.HasFlag("verbose");
bool dryRun = cli.HasFlag("dry-run", shortNames: []); // Do not infer a 'd' short name
string[] labels = cli.GetRequiredStrings();

Approachable, easy, opinionated

Working in happy-path scenarios, UtilityCli allows you to simply call Parse(args) in your console application and then extract elements into strongly-typed values. UtilityCli applies some opinionated formatting to your command-line to achieve an easy-to-use API.

  • Option names are always prefixed with a double dash; e.g. --name
  • Option short names must always be single characters, and are recognized with a single dash; e.g. -n
  • POSIX bundling is always enabled; e.g. -name would match options with short names n, a, m, e (regardless of order)
  • Option names (and short names) are case-sensitive; aliases can be specified with different casing if desired

UtilityCli is not intended for CLI applications that are distributed to other users; it's intended for utility applications you create for yourself or your team. Because UtilityCli does not require the CLI to be modeled up-front, there are functional limitations. Most notably:

  • Unmatched options and arguments do not cause parsing to fail
  • Options must always be extracted before arguments (to avoid ambiguity)

With a fully-modeled System.CommandLine CLI, there is no ambiguity in terms of how options and arguments are extracted. Using UtilityCli and skipping the step of modeling your CLI can introduce such ambiguities. For utility apps you author for yourself or your team, and even for single-use applications though, this trade-off can save time and frustration.

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 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. 
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
0.1.4-preview 413 1/3/2024
0.1.3-preview 110 12/15/2023
0.1.2-preview 84 12/15/2023
0.1.1-preview 92 12/14/2023