Ookii.CommandLine 2.4.0

.NET 6.0 .NET Standard 2.0 .NET Framework 2.0
NuGet\Install-Package Ookii.CommandLine -Version 2.4.0
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.
dotnet add package Ookii.CommandLine --version 2.4.0
<PackageReference Include="Ookii.CommandLine" Version="2.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ookii.CommandLine --version 2.4.0
#r "nuget: Ookii.CommandLine, 2.4.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Ookii.CommandLine as a Cake Addin
#addin nuget:?package=Ookii.CommandLine&version=2.4.0

// Install Ookii.CommandLine as a Cake Tool
#tool nuget:?package=Ookii.CommandLine&version=2.4.0

Ookii.CommandLine

Ookii.CommandLine enables comprehensive command line argument parsing for .Net applications. It allows you to easily define required, optional, positional and named arguments, parse the command line, and generate usage information. It is provided in versions for .Net Framework 2.0 and later, .Net Standard 2.0, and .Net 6.0 and later.

Accompanying code snippets are available on the Visual Studio marketplace.

Overview

Ookii.CommandLine is a library that helps you to parse command line arguments for your applications. It allows you to easily define a set of accepted arguments, and then parse the command line supplied to your application for those arguments. In addition, it allows you to generate usage help from the arguments that you defined which you can display to the user.

Ookii.CommandLine can be used with any kind of .Net application, whether Console, Windows Forms, or WPF. Although a limited subset of functionality – particularly related around generating usage help text – is geared primarily towards console applications that are invoked from the command prompt, the main command line parsing functionality is usable in any application that needs to process command line arguments.

To define a set of command line arguments, you create a class that will hold their values. The constructor parameters and properties of that class determine the set of arguments that are accepted. Attributes can be used to specify things such as the argument name and whether or not an argument is required, and to specify descriptions used to customize the usage help.

Command line parsing is done in a way that is similar to that used by Windows PowerShell. Each argument has a name, and can be supplied by name on the command line. An argument can also be positional, in which case it can be supplied without the name. Arguments can be required or optional, and there is support for switch arguments (which don't need a value but are either present or not) and arguments with multiple values. Various aspects of the parsing, such as the argument name prefix (typically a / or a -), can be customized.

For example, the following class defines four arguments: a required positional argument, an optional positional argument, a named argument, and a switch argument:

class MyArguments
{
    [CommandLineArgument(Position = 0, IsRequired = true)]
    public string RequiredArgument { get; set; }
    [CommandLineArgument(Position = 1)]
    public int OptionalArgument { get; set; }
    [CommandLineArgument]
    public DateTime NamedArgument { get; set; }
    [CommandLineArgument]
    public bool SwitchArgument { get; set; }
}

The application using these arguments would have the following usage syntax (this kind of usage help can be generated by Ookii.CommandLine, and can be customized to include argument descriptions):

Usage: MyApplication.exe [-RequiredArgument] <String> [[-OptionalArgument] <Number>] [-NamedArgument <DateTime>] [-SwitchArgument]

An example invocation of this application, specifying all the arguments, would look like this:

MyApplication.exe foo 42 -SwitchArgument -NamedArgument 2019-08-14

There is also functionality for creating command line utilities that perform multiple operations, each with their own arguments (these are called ShellCommands in Ookii.CommandLine).

Please see the Documentation for more information, and also check out the Class Library documentation.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net20 net35 net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 2.0

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Ookii.CommandLine:

Package Downloads
Ookii.CommandLine.Sample

A sample for Ookii.CommandLine demonstrating how to define and parse arguments. The sample is provided for C# and Visual Basic.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Ookii.CommandLine:

Repository Stars
Ourpalm/ILRuntime
Pure C# IL Intepreter Runtime, which is fast and reliable for scripting requirement on enviorments, where jitting isn't possible.
Version Downloads Last updated
2.4.0 81 9/1/2022
2.3.0 12,760 9/5/2019
2.2.0 80,885 2/6/2013
2.1.0 2,236 2/20/2012

For details, please view: https://github.com/SvenGroot/ookii.commandline/blob/master/docs/What's New in Ookii.CommandLine.md