feat(config): add ConfigResolver with CLI>file>default precedence
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
30
src/ClaudeMailbox/Config/ConfigResolver.cs
Normal file
30
src/ClaudeMailbox/Config/ConfigResolver.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using ClaudeMailbox.Cli;
|
||||
|
||||
namespace ClaudeMailbox.Config;
|
||||
|
||||
public static class ConfigResolver
|
||||
{
|
||||
public static DaemonConfig Build(string[] serveArgs, FileConfig file)
|
||||
{
|
||||
var cliPort = ParseIntOption(serveArgs, "--port");
|
||||
var cliBind = ClientCommands.GetOption(serveArgs, "--bind");
|
||||
var cliDbPath = ClientCommands.GetOption(serveArgs, "--db-path");
|
||||
|
||||
var port = cliPort ?? file.Port ?? DaemonConfig.DefaultPort;
|
||||
var bind = cliBind ?? file.Bind ?? DaemonConfig.DefaultBindAddress;
|
||||
var dbPathRaw = cliDbPath ?? file.DbPath ?? Paths.DefaultDbPath();
|
||||
|
||||
return new DaemonConfig
|
||||
{
|
||||
Port = port,
|
||||
BindAddress = bind,
|
||||
DbPath = Paths.Expand(dbPathRaw),
|
||||
};
|
||||
}
|
||||
|
||||
private static int? ParseIntOption(string[] args, string name)
|
||||
{
|
||||
var raw = ClientCommands.GetOption(args, name);
|
||||
return int.TryParse(raw, out var v) ? v : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user