McMaster.Extensions.CommandLineUtils 2.1.0-alpha

Prefix Reserved
This is a prerelease version of McMaster.Extensions.CommandLineUtils.
There is a newer version of this package available.
See the version list below for details.
dotnet add package McMaster.Extensions.CommandLineUtils --version 2.1.0-alpha
                    
NuGet\Install-Package McMaster.Extensions.CommandLineUtils -Version 2.1.0-alpha
                    
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="McMaster.Extensions.CommandLineUtils" Version="2.1.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="2.1.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="McMaster.Extensions.CommandLineUtils" />
                    
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 McMaster.Extensions.CommandLineUtils --version 2.1.0-alpha
                    
#r "nuget: McMaster.Extensions.CommandLineUtils, 2.1.0-alpha"
                    
#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.
#addin nuget:?package=McMaster.Extensions.CommandLineUtils&version=2.1.0-alpha&prerelease
                    
Install McMaster.Extensions.CommandLineUtils as a Cake Addin
#tool nuget:?package=McMaster.Extensions.CommandLineUtils&version=2.1.0-alpha&prerelease
                    
Install McMaster.Extensions.CommandLineUtils as a Cake Tool

Usage

See detailed examples, see the samples for more examples, such as:

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);
    }
}

Product 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.  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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (81)

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 (105)

Showing the top 20 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 Nitro the awesome Monaco based GraphQL IDE.
cobbr/Covenant
Covenant is a collaborative .NET C2 framework for red teamers.
xunit/xunit
xUnit.net is a free, open source, community-focused unit testing tool for .NET.
jamesmh/coravel
Near-zero config .NET library that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
ravendb/ravendb
ACID Document Database
mayuki/Cocona
Micro-framework for .NET console application. Cocona makes it easy and fast to build console applications on .NET.
fluentmigrator/fluentmigrator
Fluent migrations framework for .NET
fanliang11/surging
Surging is a micro-service engine that provides a lightweight, high-performance, modular RPC request pipeline. support Event-based Asynchronous Pattern and reactive programming ,The service engine supports http, TCP, WS,Grpc, Thrift,Mqtt, UDP, and DNS protocols. It uses ZooKeeper and Consul as a registry, and integrates it. Hash, random, polling, Fair Polling as a load balancing algorithm, built-in service governance to ensure reliable RPC communication, the engine contains Diagnostic, link tracking for protocol and middleware calls, and integration SkyWalking Distributed APM
dotnet-script/dotnet-script
Run C# scripts from the .NET CLI.
loic-sharma/BaGet
A lightweight NuGet and symbol server
scriptcs/scriptcs
Write C# apps with a text editor, nuget and the power of Roslyn!
MichaCo/CacheManager
CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
natemcmaster/CommandLineUtils
Command line parsing and utilities for .NET
AppMetrics/AppMetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
stryker-mutator/stryker-net
Mutation testing for .NET core and .NET framework!
OmniSharp/omnisharp-roslyn
OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
Cysharp/ConsoleAppFramework
Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
microsoft/AdaptiveCards
A new way for developers to exchange card content in a common and consistent way.
Version Downloads Last updated
4.1.1 1,965,569 2/19/2024
4.1.0 781,056 8/26/2023
4.0.2 1,790,354 11/19/2022
4.0.1 2,214,611 2/1/2022
4.0.0 677,708 12/27/2021
4.0.0-beta.74 50,622 1/22/2021
4.0.0-beta.56 1,244 1/17/2021
3.1.0 3,205,135 1/10/2021
3.1.0-rc.371 5,709 11/7/2020
3.1.0-beta.356 1,392 9/13/2020
3.1.0-beta.336 599 8/28/2020
3.0.0 2,899,343 3/29/2020
3.0.0-rc.289 4,991 3/21/2020
3.0.0-alpha.268 2,507 3/9/2020
2.6.0 775,313 3/8/2020
2.5.1 253,060 2/7/2020
2.5.0 268,230 1/2/2020
2.4.4 213,518 11/11/2019
2.4.3 29,273 11/1/2019 2.4.3 is deprecated because it has critical bugs.
2.4.2 192,968 9/24/2019 2.4.2 is deprecated because it has critical bugs.
2.4.1 22,388 9/18/2019
2.4.0 18,626 9/14/2019
2.3.4 1,025,889 4/11/2019
2.3.3 212,822 3/11/2019
2.3.2 320,774 2/5/2019
2.3.1 45,114 1/19/2019
2.3.0 280,035 1/1/2019
2.2.5 1,535,595 7/2/2018
2.2.4 317,871 5/25/2018
2.2.3 32,960 5/11/2018
2.2.2 97,471 4/28/2018
2.2.1 110,716 4/11/2018
2.2.0 655,719 3/31/2018
2.2.0-rc 8,489 3/23/2018
2.2.0-beta 3,381 3/8/2018
2.2.0-alpha 3,348 2/20/2018
2.1.1 132,510 12/28/2017
2.1.0 14,561 12/13/2017
2.1.0-rc 3,328 12/7/2017
2.1.0-beta 4,190 11/22/2017
2.1.0-alpha 3,088 11/11/2017
2.0.1 18,319 10/13/2017
2.0.0 20,707 9/16/2017

2.1.0:
New features:
- Attributes. Simplify command line argument definitions by adding attributes to a class that represents options and arguments.
   - Options defined as [Option] or [Argument], [Subcommand].
   - Command parsing options can be defined with [Command] and [Subcmomand].
   - Special options include [HelpOption] and [VersionOption].
- Async from end to end. Using C# 7.1 and attribute binding, your console app can be async from top to bottom.

New API
- Added OptionAttribute, ArgumentAttribute, CommandAttribute, SubcommandAttribute, HelpOptionAttribute, and VersionOptionAttribute.
- CommandLineApplication.Execute<TApp>() - executes an app where TApp uses attributes to define its options
- CommandLineApplication.ExecuteAsync<TApp>() - sample thing, but async.
- CommandLineApplication.StopParsingHelpOption and StopParsingVerboseOption. When the help and verbose options are matched
  against a command-line flag, the parsing will stop by default. You can turn this off by setting these options if you
  want OnExecute to be invoked no matter what.
- CommandLineApplication.HandleResponseFiles - the parser can treat arguments that begin with '@' as response files.
  Response files contain arguments that will be treated as if they were passed on command line.

Minor bug fixes:
- Add return types to .VerboseOption() and ensure .HasValue() is true when HelpOption or VerboseOption are matched
- Fix a NullReferenceException in some edge cases when parsing args