UtilityCli 0.1.2-preview

This is a prerelease version of UtilityCli.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package UtilityCli --version 0.1.2-preview
                    
NuGet\Install-Package UtilityCli -Version 0.1.2-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.2-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UtilityCli" Version="0.1.2-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.2-preview
                    
#r "nuget: UtilityCli, 0.1.2-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.2-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.2-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=UtilityCli&version=0.1.2-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.

using UtilityCli;

// --org dotnet --repo runtime area-System.Security untriaged --dry-run --issue 40075 --pr 40075
string org = cli.GetRequiredString("org", aliases: ["owner"]);
string repo = cli.GetRequiredString("repo");
int[]? issues = cli.GetInt32s("issue");
int[]? prs = cli.GetInt32s("pr");
bool dryRun = cli.HasFlag("dry-run", shortNames: null);
string[] labels = cli.GetRequiredStrings();

foreach (int issue in issues ?? [])
{
    Console.WriteLine($"Add labels to {org}/{repo}#{issue} (issue): {string.Join(", ", labels)}");
}

foreach (int pr in prs ?? [])
{
    Console.WriteLine($"Add labels to {org}/{repo}#{pr} (PR): {string.Join(", ", labels)}");
}

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 --name
  • Option short names must always be single characters, and are recognized with a single -n

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 trade-offs in terms of the end-user's experience rearranging options and arguments on the command-line. With a fully-modeled System.CommandLine CLI, there is no ambiguity in terms of how commands, 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.

If your application matures, UtilityCli can mature with you. The APIs allow gradual or full CLI modeling to occur before parsing, reaching the same point of zero ambiguity you get when using System.CommandLine directly-after all, UtilityCli is simply a convenience layer that wraps around it. A fully-modeled UtilityCli application can easily be refactored to directly use System.CommandLine as well.

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