tony / oxwm

Added validate config flag. Browse files
tonybanters committed 2026-02-17 parent c9d3f92 commit 79abec94bf202af5b8dee6630c0c9c7ebeb01e14
Showing 1 changed file with 34 additions and 0 deletions. UnifiedSplit
+34 −0 src/main.zig
@@ -88,6 +88,7 @@ fn print_help() void {
88 88 \\OPTIONS:
89 89 \\ --init Create default config in ~/.config/oxwm/config.lua
90 90 \\ --config <PATH> Use custom config file
91 + \\ --validate Validate config file without starting window manager
91 92 \\ --version Print version information
92 93 \\ --help Print this help message
93 94 \\
@@ -132,6 +133,31 @@ fn init_config(allocator: std.mem.Allocator) void {
132 133 std.debug.print("No compilation needed - changes take effect immediately!\n", .{});
133 134 }
134 135
136 +fn validate_config(allocator: std.mem.Allocator, config_path: []const u8) !void {
137 + config = config_mod.Config.init(allocator);
138 + defer config.deinit();
139 +
140 + if (!lua.init(&config)) {
141 + std.debug.print("error: failed to initialize lua\n", .{});
142 + std.process.exit(1);
143 + }
144 + defer lua.deinit();
145 +
146 + _ = std.fs.cwd().statFile(config_path) catch |err| {
147 + std.debug.print("error: config file not found: {s}\n", .{config_path});
148 + std.debug.print(" {}\n", .{err});
149 + std.process.exit(1);
150 + };
151 +
152 + if (lua.load_file(config_path)) {
153 + std.debug.print("✓ config valid: {s}\n", .{config_path});
154 + std.process.exit(0);
155 + } else {
156 + std.debug.print("✗ config validation failed\n", .{});
157 + std.process.exit(1);
158 + }
159 +}
160 +
135 161 pub fn main() !void {
136 162 const allocator = gpa.allocator();
137 163 defer _ = gpa.deinit();
@@ -140,6 +166,7 @@ pub fn main() !void {
140 166 defer allocator.free(default_config_path);
141 167
142 168 var config_path: []const u8 = default_config_path;
169 + var validate_mode: bool = false;
143 170 var args = std.process.args();
144 171 _ = args.skip();
145 172 while (args.next()) |arg| {
@@ -154,9 +181,16 @@ pub fn main() !void {
154 181 } else if (std.mem.eql(u8, arg, "--init")) {
155 182 init_config(allocator);
156 183 return;
184 + } else if (std.mem.eql(u8, arg, "--validate")) {
185 + validate_mode = true;
157 186 }
158 187 }
159 188
189 + if (validate_mode) {
190 + try validate_config(allocator, config_path);
191 + return;
192 + }
193 +
160 194 std.debug.print("oxwm starting\n", .{});
161 195
162 196 config = config_mod.Config.init(allocator);