Skip to content

Commit

Permalink
add config support for non optional strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Dec 20, 2023
1 parent 6ec8fc8 commit ea709f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
34 changes: 22 additions & 12 deletions src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,28 @@ pub fn updateConfiguration(server: *Server, new_config: configuration.Configurat

inline for (std.meta.fields(Config)) |field| {
if (@field(new_cfg, field.name)) |new_config_value| {
if (@TypeOf(new_config_value) == []const u8) {
if (@field(server.config, field.name) == null or
!std.mem.eql(u8, @field(server.config, field.name).?, new_config_value))
{
log.info("set config option '{s}' to '{s}'", .{ field.name, new_config_value });
@field(server.config, field.name) = try config_arena.dupe(u8, new_config_value);
}
} else {
if (@field(server.config, field.name) != new_config_value) {
log.info("set config option '{s}' to '{any}'", .{ field.name, new_config_value });
@field(server.config, field.name) = new_config_value;
}
const old_config_value = @field(server.config, field.name);
switch (@TypeOf(old_config_value)) {
?[]const u8 => {
const override_old_value =
if (old_config_value) |old_value| !std.mem.eql(u8, old_value, new_config_value) else true;
if (override_old_value) {
log.info("set config option '{s}' to '{s}'", .{ field.name, new_config_value });
@field(server.config, field.name) = try config_arena.dupe(u8, new_config_value);
}
},
[]const u8 => {
if (!std.mem.eql(u8, old_config_value, new_config_value)) {
log.info("set config option '{s}' to '{s}'", .{ field.name, new_config_value });
@field(server.config, field.name) = try config_arena.dupe(u8, new_config_value);
}
},
else => {
if (old_config_value != new_config_value) {
log.info("set config option '{s}' to '{any}'", .{ field.name, new_config_value });
@field(server.config, field.name) = new_config_value;
}
},
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/config_gen/config_gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const ConfigOption = struct {
default: []const u8,

fn getTypescriptType(self: ConfigOption) error{UnsupportedType}![]const u8 {
return if (std.mem.eql(u8, self.type, "?[]const u8"))
return if (std.mem.eql(u8, self.type, "[]const u8"))
"string"
else if (std.mem.eql(u8, self.type, "?[]const u8"))
"string"
else if (std.mem.eql(u8, self.type, "bool"))
"boolean"
Expand Down

0 comments on commit ea709f4

Please sign in to comment.