Git Product home page Git Product logo

martinsmith1968 / ookii.commandline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from svengroot/ookii.commandline

0.0 2.0 0.0 1.83 MB

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.

License: Microsoft Public License

C# 82.73% PowerShell 1.26% Pascal 4.59% Visual Basic .NET 6.30% Vim Snippet 5.13%

ookii.commandline's Introduction

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.

ookii.commandline's People

Contributors

svengroot avatar

Watchers

James Cloos avatar Martin Smith avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.