Skip to content

deniszykov/commandline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotnet_build

Introduction

A simple getopt styled command line library.

Installation

Install-Package deniszykov.CommandLine

.NET Framework Example

For .NET Core Hosted environment:

Install-Package deniszykov.CommandLine.Hosted

.NET Core Hosted Example

Quick Start

To start, you need to configure the entry point to the application:

public class Program
{

  private static int Main(string[] arguments) =>
    CommandLine
      .CreateFromArguments(arguments)
      .Use<Program>() // set class with verbs/commands
      .Run();

  //
  // Usage: myapp.exe hello --name <name>
  // 
  public static int Hello(string name)
  //                  ^            ^
  //                 Verb        Option
  {
    Console.WriteLine("Hello " + name + "!");
    return 0; // exit code
  }  

}

Example Code / .NET Hosted Example Code

CommandLine relies on reflection to find method to invoke.
This method should return int value which is interpreted as Exit Code of application.
Asynchronous entry points and methods are also supported. To do this, use method RunAsync() and Task<int> as return type.

When you could request help for your application:

> myapp /?

This test application. Type /? for help.

  Verbs:
    HELLO    Says hello to specified 'name'.

Or invoke Hello(string name) with following command:

> myapp hello --name Jake

Hello Jake!

Documentation

About

Getopt styled command line parser.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages