From 84af11e1eb3fd88c64818feb58570886c74fc3a5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 2 Aug 2022 09:25:36 -0700 Subject: [PATCH] detect config file load in config file --- src/main.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.zig b/src/main.zig index d179f0f9c..7ac523102 100644 --- a/src/main.zig +++ b/src/main.zig @@ -48,6 +48,7 @@ pub fn main() !void { // TODO(mitchellh): support nesting (config-file in a config file) // TODO(mitchellh): detect cycles when nesting if (config.@"config-file".list.items.len > 0) { + const len = config.@"config-file".list.items.len; const cwd = std.fs.cwd(); for (config.@"config-file".list.items) |path| { var file = try cwd.openFile(path, .{}); @@ -57,6 +58,12 @@ pub fn main() !void { var iter = cli_args.lineIterator(buf_reader.reader()); try cli_args.parse(Config, alloc, &config, &iter); + + // We don't currently support adding more config files to load + // from within a loaded config file. This can be supported + // later. + if (config.@"config-file".list.items.len > len) + return error.ConfigFileInConfigFile; } } log.info("config={}", .{config});