Skip to content

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.

master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 

README.md

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 available for .Net Framework 2.0 and later, and .Net Standard 2.0.

Ookii.CommandLine can be added to your project in Visual Studio via NuGet. A sample is also available via NuGet. If you wish to use the code snippets, please download the release from GitHub; they are not included with the NuGet package.

Symbols and source code for the NuGet package are available from SymbolSource. They can be automatically used in Visual Studio by following these instructions.

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.

Please see the Documentation for more informaton.

About

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.

Resources

License

You can’t perform that action at this time.