McMaster.Extensions.CommandLineUtils
2.2.0-rc
Prefix Reserved
See the version list below for details.
dotnet add package McMaster.Extensions.CommandLineUtils --version 2.2.0-rc
NuGet\Install-Package McMaster.Extensions.CommandLineUtils -Version 2.2.0-rc
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.0-rc" />
paket add McMaster.Extensions.CommandLineUtils --version 2.2.0-rc
#r "nuget: McMaster.Extensions.CommandLineUtils, 2.2.0-rc"
// Install McMaster.Extensions.CommandLineUtils as a Cake Addin #addin nuget:?package=McMaster.Extensions.CommandLineUtils&version=2.2.0-rc&prerelease // Install McMaster.Extensions.CommandLineUtils as a Cake Tool #tool nuget:?package=McMaster.Extensions.CommandLineUtils&version=2.2.0-rc&prerelease
CommandLineApplication
is the main entry point for most console apps parsing. There are two primary ways to use this API, using the builder pattern and attributes.
Attribute API
using System;
using McMaster.Extensions.CommandLineUtils;
[HelpOption]
public class Program
{
public static int Main(string[] args)
=> CommandLineApplication.Execute<Program>(args);
[Option(Description = "The subject")]
public string Subject { get; }
private void OnExecute()
{
var subject = Subject ?? "world";
Console.WriteLine($"Hello {subject}!");
}
}
Builder API
using System;
using McMaster.Extensions.CommandLineUtils;
public class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication();
app.HelpOption();
var optionSubject = app.Option("-s|--subject <SUBJECT>", "The subject", CommandOptionType.SingleValue);
app.OnExecute(() =>
{
var subject = optionSubject.HasValue()
? optionSubject.Value()
: "world";
Console.WriteLine($"Hello {subject}!");
return 0;
});
return app.Execute(args);
}
}
Utilities
The library also includes other utilities for interaction with the console. These include:
ArgumentEscaper
- use to escape arguments when starting a new command line process.var args = new [] { "Arg1", "arg with space", "args ' with \"" quotes" }; Process.Start("echo", ArgumentEscaper.EscapeAndConcatenate(args));
Prompt
- for getting feedback from users. A few examples:// allows y/n responses Prompt.GetYesNo("Do you want to proceed?"); // masks input as '*' Prompt.GetPassword("Password: ");
DotNetExe
- finds the path to the dotnet.exe file used to start a .NET Core processProcess.Start(DotNetExe.FullPathOrDefault(), "run");
And more! See the docs for more API, such as IConsole
, IReporter
, and others.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.6 is compatible. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- System.ValueTuple (>= 4.4.0)
-
.NETStandard 1.6
- System.ComponentModel.Annotations (>= 4.1.0)
- System.Diagnostics.Process (>= 4.1.0)
- System.Threading.Thread (>= 4.0.0)
- System.ValueTuple (>= 4.4.0)
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 4.1.0)
NuGet packages (82)
Showing the top 5 NuGet packages that depend on McMaster.Extensions.CommandLineUtils:
Package | Downloads |
---|---|
McMaster.Extensions.Hosting.CommandLine
Provides command-line parsing API integration with the generic host API (Microsoft.Extensions.Hosting). |
|
QuantConnect.Configuration
QuantConnect LEAN Engine: Configuration Project - The Config and argument parser implementation |
|
FlubuCore
A cross platform build and deployment automation system for building projects and executing deployment scripts using C# code. Documentation can be found at: https://github.com/dotnetcore/FlubuCore Detailed examples can be found at: https://github.com/dotnetcore/FlubuCore.Examples |
|
KubeOps
This is an operator sdk written in c#. It enables a developer to create a custom controller for CRDs (CustomResourceDefinitions) that runs on kubernetes. |
|
Faithlife.Build
A build automation system using C# build scripts. |
GitHub repositories (108)
Showing the top 5 popular GitHub repositories that depend on McMaster.Extensions.CommandLineUtils:
Repository | Stars |
---|---|
icsharpcode/ILSpy
.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
|
|
QuantConnect/Lean
Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
|
|
ChilliCream/graphql-platform
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
|
|
xunit/xunit
xUnit.net is a free, open source, community-focused unit testing tool for .NET.
|
|
cobbr/Covenant
Covenant is a collaborative .NET C2 framework for red teamers.
|
Version | Downloads | Last updated | |
---|---|---|---|
4.1.1 | 1,087,910 | 2/19/2024 | |
4.1.0 | 720,431 | 8/26/2023 | |
4.0.2 | 1,624,845 | 11/19/2022 | |
4.0.1 | 2,142,329 | 2/1/2022 | |
4.0.0 | 661,496 | 12/27/2021 | |
4.0.0-beta.74 | 49,102 | 1/22/2021 | |
4.0.0-beta.56 | 1,216 | 1/17/2021 | |
3.1.0 | 2,961,923 | 1/10/2021 | |
3.1.0-rc.371 | 5,631 | 11/7/2020 | |
3.1.0-beta.356 | 1,364 | 9/13/2020 | |
3.1.0-beta.336 | 567 | 8/28/2020 | |
3.0.0 | 2,718,173 | 3/29/2020 | |
3.0.0-rc.289 | 4,957 | 3/21/2020 | |
3.0.0-alpha.268 | 2,479 | 3/9/2020 | |
2.6.0 | 734,169 | 3/8/2020 | |
2.5.1 | 242,041 | 2/7/2020 | |
2.5.0 | 255,296 | 1/2/2020 | |
2.4.4 | 206,065 | 11/11/2019 | |
2.4.3 | 28,655 | 11/1/2019 | |
2.4.2 | 186,081 | 9/24/2019 | |
2.4.1 | 21,121 | 9/18/2019 | |
2.4.0 | 18,039 | 9/14/2019 | |
2.3.4 | 1,009,554 | 4/11/2019 | |
2.3.3 | 206,049 | 3/11/2019 | |
2.3.2 | 315,555 | 2/5/2019 | |
2.3.1 | 44,224 | 1/19/2019 | |
2.3.0 | 267,477 | 1/1/2019 | |
2.2.5 | 1,436,011 | 7/2/2018 | |
2.2.4 | 291,724 | 5/25/2018 | |
2.2.3 | 31,884 | 5/11/2018 | |
2.2.2 | 94,772 | 4/28/2018 | |
2.2.1 | 107,808 | 4/11/2018 | |
2.2.0 | 577,812 | 3/31/2018 | |
2.2.0-rc | 8,271 | 3/23/2018 | |
2.2.0-beta | 3,181 | 3/8/2018 | |
2.2.0-alpha | 3,133 | 2/20/2018 | |
2.1.1 | 129,978 | 12/28/2017 | |
2.1.0 | 13,738 | 12/13/2017 | |
2.1.0-rc | 3,057 | 12/7/2017 | |
2.1.0-beta | 4,015 | 11/22/2017 | |
2.1.0-alpha | 2,873 | 11/11/2017 | |
2.0.1 | 17,627 | 10/13/2017 | |
2.0.0 | 18,181 | 9/16/2017 |
New features:
- Added more validation attributes.
- Add the `[FileExists]` attribute
- Add the `[FileOrDirectoryExists]` attribute
- Add the `[DirectoryExists]` attribute
- Add the `[LegalFilePath]` attribute
- Add the `[AllowedValues]` attribute
- Added a new, fluent API for validation.
- Added `Option().Accepts()` and `Argument().Accepts()`
- Add `.ExistingFile()`
- Add `.ExistingFileOrDirectory()`
- Add `.ExistingDirectory()`
- Add `.EmailAddress()`
- Add `.LegalFilePath()`
- Add `.MinLength(length)`
- Add `.MaxLength(length)`
- Add `.RegularExpression(pattern)`
- Add `.Values(string[] allowedValues)`
- Add `.Range(min, max)`
- Add `CommandOptionType.SingleOrNoValue`.
- Options of this type can be a switch, or have a value but only in the form `--param:value` or `--param=value`.
- Support mapping `ValueTuple<bool,T>` to `CommandOptionType.SingleOrNoValue`
- Generic commands, options, and arguments
- Added `CommandLineApplication<TModel>`. This allows associating an application with a specific .NET type
- Add support for `Option<T>` and `Argument<T>`
- Convention API
- Adds support for writing your own conventions to convert command line arguments into a .NET type
- Add API to use a dozen of built-in conventions
Other enhancements:
- Support parsing enums
- @rmcc13 - `HelpOption` can be set to be inherited by all subcommands
- @atruskie - Support for parsing double and floats
- @sebastienros - Support for case-insensitive options
- @atruskie: Add support for user-defined value parsers using `IValueParser` and `CommandLineApplication.ValueParsers`.
- Add support for constructor injection and dependency injection by providing a custom service provider
- Parse these values to boolean: T, t, F, f, 0, 1
- Add `VersionOptionFromMember` to use a property or method as the source of version information
See more details here: https://github.com/natemcmaster/CommandLineUtils/blob/master/CHANGELOG.md#v220