UtilityCli 0.1.4-preview
dotnet add package UtilityCli --version 0.1.4-preview
NuGet\Install-Package UtilityCli -Version 0.1.4-preview
<PackageReference Include="UtilityCli" Version="0.1.4-preview" />
<PackageVersion Include="UtilityCli" Version="0.1.4-preview" />
<PackageReference Include="UtilityCli" />
paket add UtilityCli --version 0.1.4-preview
#r "nuget: UtilityCli, 0.1.4-preview"
#:package UtilityCli@0.1.4-preview
#addin nuget:?package=UtilityCli&version=0.1.4-preview&prerelease
#tool nuget:?package=UtilityCli&version=0.1.4-preview&prerelease
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 namesn
,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 | Versions 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. |
-
net8.0
- System.CommandLine (>= 2.0.0-beta4.22272.1)
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 |