feat(config): load mailbox.json with CLI override in Program
This commit is contained in:
@@ -7,16 +7,15 @@ if (args.Length > 0 && args[0] is "send" or "peek" or "check" or "list")
|
||||
return await ClientCommands.RunAsync(args);
|
||||
}
|
||||
|
||||
// Strip the optional leading "serve" verb so WebApplication.CreateBuilder
|
||||
// doesn't try to treat it as an unknown flag.
|
||||
var serveArgs = (args.Length > 0 && args[0] == "serve") ? args[1..] : args;
|
||||
|
||||
var cfg = new DaemonConfig
|
||||
{
|
||||
Port = ParseInt(serveArgs, "--port", DaemonConfig.DefaultPort),
|
||||
BindAddress = ClientCommands.GetOption(serveArgs, "--bind") ?? DaemonConfig.DefaultBindAddress,
|
||||
DbPath = Paths.Expand(ClientCommands.GetOption(serveArgs, "--db-path") ?? Paths.DefaultDbPath()),
|
||||
};
|
||||
var explicitConfig = ClientCommands.GetOption(serveArgs, "--config");
|
||||
var defaultConfig = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
|
||||
"ClaudeMailbox", "mailbox.json");
|
||||
|
||||
var fileConfig = FileConfig.Load(explicitConfig, defaultConfig);
|
||||
var cfg = ConfigResolver.Build(serveArgs, fileConfig);
|
||||
|
||||
var builder = ServerHost.CreateBuilder(cfg, serveArgs);
|
||||
builder.WebHost.UseUrls(cfg.BaseUrl);
|
||||
@@ -38,10 +37,4 @@ catch (IOException ex) when (ex.Message.Contains("address already in use", Strin
|
||||
return 3;
|
||||
}
|
||||
|
||||
static int ParseInt(string[] args, string name, int fallback)
|
||||
{
|
||||
var raw = ClientCommands.GetOption(args, name);
|
||||
return int.TryParse(raw, out var v) ? v : fallback;
|
||||
}
|
||||
|
||||
public partial class Program { }
|
||||
|
||||
Reference in New Issue
Block a user