60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using Mono.Options;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace OwnChar.Server;
|
|
|
|
internal class ServerOptions
|
|
{
|
|
private readonly OptionSet options;
|
|
|
|
public string? DbServer { get; set; }
|
|
public string? DbDatabase { get; set; }
|
|
public string? DbUser { get; set; }
|
|
public string? DbPassword { get; set; }
|
|
public string? ApiUrl { get; set; }
|
|
|
|
public ServerOptions(string[] args)
|
|
{
|
|
options = new()
|
|
{
|
|
{
|
|
"url=",
|
|
"Sets the api server url.",
|
|
dbhost => DbServer = dbhost
|
|
},
|
|
{
|
|
"host=",
|
|
"Sets the database server address.",
|
|
dbhost => DbServer = dbhost
|
|
},
|
|
{
|
|
"db=",
|
|
"Sets the database name.",
|
|
dbhost => DbServer = dbhost
|
|
},
|
|
{
|
|
"usr=",
|
|
"Sets the database user.",
|
|
dbhost => DbServer = dbhost
|
|
},
|
|
{
|
|
"pwd=",
|
|
"Sets the database password.",
|
|
dbhost => DbServer = dbhost
|
|
}
|
|
};
|
|
|
|
options.Parse(args);
|
|
}
|
|
|
|
[MemberNotNullWhen(true, nameof(ApiUrl), nameof(DbServer), nameof(DbDatabase), nameof(DbUser), nameof(DbPassword))]
|
|
public bool IsValid()
|
|
{
|
|
return !string.IsNullOrWhiteSpace(ApiUrl)
|
|
&& !string.IsNullOrWhiteSpace(DbServer)
|
|
&& !string.IsNullOrWhiteSpace(DbDatabase)
|
|
&& !string.IsNullOrWhiteSpace(DbUser)
|
|
&& !string.IsNullOrWhiteSpace(DbPassword);
|
|
}
|
|
}
|