holy! the server app is finished & model is nice now
This commit is contained in:
59
OwnChar.Server/ServerOptions.cs
Normal file
59
OwnChar.Server/ServerOptions.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user