forked from mayuki/Cocona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
56 lines (49 loc) · 1.51 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using Cocona;
namespace CoconaSample.GettingStarted.SubCommandApp
{
[HasSubCommands(typeof(SubCommands), Description = "Nested sub-commands")]
class Program
{
static void Main(string[] args)
{
CoconaApp.Run<Program>(args);
}
[Command(Description = "Say hello")]
public void Hello([Option('u', Description = "Print a name converted to upper-case.")]bool toUpperCase, [Argument(Description = "Your name")]string name)
{
Console.WriteLine($"Hello {(toUpperCase ? name.ToUpper() : name)}!");
}
[Command(Description = "Say goodbye")]
public void Bye([Option('l', Description = "Print a name converted to lower-case.")]bool toLowerCase, [Argument(Description = "Your name")]string name)
{
Console.WriteLine($"Goodbye {(toLowerCase ? name.ToLower() : name)}!");
}
}
// ./myapp sub-commands [command]
[HasSubCommands(typeof(SubSubCommands))]
class SubCommands
{
public void Konnichiwa()
{
Console.WriteLine("Konnichiwa!");
}
public void Hello()
{
Console.WriteLine("Hello!");
}
}
// ./myapp sub-commands sub-sub-commands [command]
class SubSubCommands
{
public void Foobar()
{
Console.WriteLine("Foobar!");
}
[PrimaryCommand]
public void Primary(string value)
{
Console.WriteLine($"value={value}");
}
}
}