fix error with IP address in server

This commit is contained in:
Sharikov P.P.
2026-01-16 10:16:24 +07:00
parent dab2acd57b
commit be23f56867
3 changed files with 35 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
"profiles": { "profiles": {
"f-cln": { "f-cln": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "-p 3113" "commandLineArgs": "--port 3113 -i 172.22.176.1"
} }
} }
} }

View File

@@ -20,13 +20,44 @@ namespace f_srv
Option<IPAddress> ipOption = new("address", new[] { "--ip", "-i" }) Option<IPAddress> ipOption = new("address", new[] { "--ip", "-i" })
{ {
Description = "IP адрес для прослушивания (по умолчанию: все интерфейсы)", Description = "IP адрес для прослушивания (по умолчанию: все интерфейсы)",
DefaultValueFactory = parseResult => IPAddress.Any DefaultValueFactory = parseResult => IPAddress.Any,
CustomParser = result =>
{
if (result.Tokens.Count != 1)
{
result.AddError("--address requires one argument");
return IPAddress.Any;
}
return IPAddress.Parse(result.Tokens.Single().Value);
}
}; };
Option<int> portOption = new("port", new[] { "--port", "-p" }) Option<int> portOption = new("port", new[] { "--port", "-p" })
{ {
Description = "Порт для прослушивания (по умолчанию: 1771)", Description = "Порт для прослушивания (по умолчанию: 1771)",
DefaultValueFactory = parseResult => 1771 DefaultValueFactory = parseResult => 1771,
CustomParser = result =>
{
if (!result.Tokens.Any())
{
return 1771;
}
if (int.TryParse(result.Tokens.Single().Value, out var delay))
{
if (delay < 1)
{
result.AddError("Must be greater than 0");
}
return delay;
}
else
{
result.AddError("Not an int.");
return 0; // Ignored.
}
}
}; };
var rootCommand = new RootCommand("Сервер для получения строк и отправки их в обратном порядке") var rootCommand = new RootCommand("Сервер для получения строк и отправки их в обратном порядке")

View File

@@ -2,7 +2,7 @@
"profiles": { "profiles": {
"f-srv": { "f-srv": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "--port 3113" "commandLineArgs": "--port 3113 -i 192.168.15.128"
} }
} }
} }