feat: add NATS.Server.Host console app with basic CLI arguments
This commit is contained in:
@@ -1,2 +1,40 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
// src/NATS.Server.Host/Program.cs
|
||||
using NATS.Server;
|
||||
|
||||
var options = new NatsOptions();
|
||||
|
||||
// Simple CLI argument parsing
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
switch (args[i])
|
||||
{
|
||||
case "-p" or "--port" when i + 1 < args.Length:
|
||||
options.Port = int.Parse(args[++i]);
|
||||
break;
|
||||
case "-a" or "--addr" when i + 1 < args.Length:
|
||||
options.Host = args[++i];
|
||||
break;
|
||||
case "-n" or "--name" when i + 1 < args.Length:
|
||||
options.ServerName = args[++i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var server = new NatsServer(options);
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
Console.CancelKeyPress += (_, e) =>
|
||||
{
|
||||
e.Cancel = true;
|
||||
cts.Cancel();
|
||||
};
|
||||
|
||||
Console.WriteLine($"[NATS] Listening on {options.Host}:{options.Port}");
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(cts.Token);
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
|
||||
Console.WriteLine("[NATS] Server stopped.");
|
||||
|
||||
Reference in New Issue
Block a user