-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
26 lines (24 loc) · 1.06 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
using CommandLine;
namespace nats_tools
{
public static class Program
{
static int Main(string[] args)
{
return Parser.Default.ParseArguments(args, typeof(ListenOptions), typeof(SendOptions), typeof(RequestOptions), typeof(ReplyOptions), typeof(StatOptions))
.MapResult(
(ListenOptions opts) => RunCommand<ListenCommand, ListenOptions>(opts),
(RequestOptions opts) => RunCommand<RequestCommand, RequestOptions>(opts),
(SendOptions opts) => RunCommand<SendCommand, SendOptions>(opts),
(ReplyOptions opts) => RunCommand<ReplyCommand, ReplyOptions>(opts),
(StatOptions opts) => RunCommand<StatCommand, StatOptions>(opts),
errs => 1);
}
static int RunCommand<TCommand, TOption>(TOption options) where TOption : AbstractNatsOptions where TCommand : AbstractNatsCommand<TOption>, new()
{
var command = new TCommand();
command.Init(options);
return command.Run();
}
}
}