feat(headless): complete portable single-session host

This commit is contained in:
Erik 2026-07-27 07:36:53 +02:00
parent fbebb91848
commit f8cb840fb1
30 changed files with 3571 additions and 32 deletions

View file

@ -0,0 +1,83 @@
namespace AcDream.Headless.Configuration;
internal sealed record HeadlessCommandLine(
string Command,
string ConfigurationPath,
HeadlessPathOverrides Paths)
{
internal static HeadlessCommandLine Parse(
IReadOnlyList<string> arguments)
{
ArgumentNullException.ThrowIfNull(arguments);
if (arguments.Count < 3)
throw new HeadlessCommandLineException("Missing command options.");
string command = arguments[0];
if (command is not ("validate" or "run"))
throw new HeadlessCommandLineException("Unknown command.");
string? configurationPath = null;
string? configDirectory = null;
string? dataDirectory = null;
string? cacheDirectory = null;
for (int index = 1; index < arguments.Count; index += 2)
{
if (index + 1 >= arguments.Count)
{
throw new HeadlessCommandLineException(
"Every command option requires a value.");
}
string name = arguments[index];
string value = arguments[index + 1];
if (string.IsNullOrWhiteSpace(value))
{
throw new HeadlessCommandLineException(
"Command option values cannot be empty.");
}
switch (name)
{
case "--config":
SetOnce(ref configurationPath, value);
break;
case "--config-dir":
SetOnce(ref configDirectory, value);
break;
case "--data-dir":
SetOnce(ref dataDirectory, value);
break;
case "--cache-dir":
SetOnce(ref cacheDirectory, value);
break;
default:
throw new HeadlessCommandLineException(
"Unknown command option.");
}
}
if (configurationPath is null)
{
throw new HeadlessCommandLineException(
"The --config option is required.");
}
return new HeadlessCommandLine(
command,
configurationPath,
new HeadlessPathOverrides(
configDirectory,
dataDirectory,
cacheDirectory));
}
private static void SetOnce(ref string? destination, string value)
{
if (destination is not null)
{
throw new HeadlessCommandLineException(
"Command options cannot be repeated.");
}
destination = value;
}
}