Need help with CLAP?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

adrianaisemberg
217 Stars 40 Forks MIT License 191 Commits 22 Opened issues

Description

CLAP: A Kick-Ass .NET Command-Line Parser

Services available

!
?

Need anything else?

Contributors list

# 331,937
C#
Shell
166 commits
# 668,641
C#
Shell
4 commits
# 609,844
C#
Shell
3 commits
# 109,787
C#
Univers...
logging...
c-sharp
2 commits
# 57,065
mocking...
CSS
C
simulat...
1 commit
# 169,140
luajit
openres...
c-sharp
CSS
1 commit

CLAP: A Kick-Ass .NET Command-Line Parser

Full Documentation and Samples

http://adrianaisemberg.github.com/CLAP

Basic example: One verb, Some parameters

class Program
{
    public static void Main(string[] args)
    {
        Parser.Run(args);
    }
}

class MyApp { [Verb] public static void Print(string text, int count) { for (int i = 0; i < count; i++) { Console.WriteLine(text); } } }

>myexe print -text:"Hello World" -count:10

Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World

Complex sample: Various verbs, global handlers, help handler, validation, default values, switches, arrays

class MyApp
{
    [Global(Aliases = "d", Description = "Launch a debugger")]
    public static void Debug()
    {
        // this is a global parameter handler.
        // it works for any verb.

    Debugger.Launch();
}

[Empty, Help]
public static void Help(string help)
{
    // this is an empty handler that prints
    // the automatic help string to the console.

    Console.WriteLine(help);
}

[Verb]
public static void Print(string text, int count)
{
    for (int i = 0; i &lt; count; i++)
    {
        Console.WriteLine(text);
    }
}

[Verb]
public static void Foo(
    [Parameter(Aliases = "t", Description = "A string parameter with an additional alias")]
    string text,

    [Parameter(Default = 5, Description = "An int parameter with a default")]
    int number,

    [MoreThan(10)]
    [LessThan(100)]
    [Parameter(Default = 42.3, Description = "A double parameter with validation and a default value")]
    double percent,

    [Parameter(Description = "A bool parameter, which can be used as a switch")]
    bool verbose,

    [Parameter(Description = "An enum parameter")]
    OptionEnum option,

    [Parameter(Description = "An array of strings")]
    string[] array)
{
    Console.WriteLine("text = {0}", text);
    Console.WriteLine("number = {0}", number);
    Console.WriteLine("percent = {0}", percent);
    Console.WriteLine("verbose = {0}", verbose);
    Console.WriteLine("option = {0}", option);
    Console.WriteLine("array = [{0}]", string.Join(",", array));
}

}

>myexe foo -t:hello -number:88 -percent:12.446 -verbose -option:Option2 -array:a,b,c,d

text = hello
number = 88
percent = 12.446
verbose = True
option = Option2
array = [a,b,c,d]

No arguments, help is printed:

myexe

Print: -text: [String] -count: [Int32]

Foo: -text/t: A string parameter with an additional alias [String] -number: An int parameter with a default [Int32, Default = 5] -percent: A double parameter with validation and a default value [Double, Default = 42.3, More than 10, Less than 100] -verbose: A bool parameter, which can be used as a switch [Boolean] -option: An enum parameter [OptionEnum] -array: An array of strings [String[]]

Global parameters: -Debug/d: Launch a debugger [Boolean]

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.