aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/cli/validate_config.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/cli/validate_config.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/cli/validate_config.zig')
-rw-r--r--vendor/libghostty-vt/src/cli/validate_config.zig78
1 files changed, 78 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/cli/validate_config.zig b/vendor/libghostty-vt/src/cli/validate_config.zig
new file mode 100644
index 00000000..5586cf29
--- /dev/null
+++ b/vendor/libghostty-vt/src/cli/validate_config.zig
@@ -0,0 +1,78 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const args = @import("args.zig");
+const Action = @import("ghostty.zig").Action;
+const Config = @import("../config.zig").Config;
+
+pub const Options = struct {
+ /// The path of the config file to validate. If this isn't specified,
+ /// then the default config file paths will be validated.
+ @"config-file": ?[:0]const u8 = null,
+
+ pub fn deinit(self: Options) void {
+ _ = self;
+ }
+
+ /// Enables "-h" and "--help" to work.
+ pub fn help(self: Options) !void {
+ _ = self;
+ return Action.help_error;
+ }
+};
+
+/// The `validate-config` command is used to validate a Ghostty config file.
+///
+/// When executed without any arguments, this will load the config from the default
+/// location.
+///
+/// Flags:
+///
+/// * `--config-file`: can be passed to validate a specific target config file in
+/// a non-default location
+pub fn run(alloc: std.mem.Allocator) !u8 {
+ var opts: Options = .{};
+ defer opts.deinit();
+
+ {
+ var iter = try args.argsIterator(alloc);
+ defer iter.deinit();
+ try args.parse(Options, alloc, &opts, &iter);
+ }
+
+ var buffer: [1024]u8 = undefined;
+ var stdout_writer = std.fs.File.stdout().writer(&buffer);
+ const stdout = &stdout_writer.interface;
+ const result = runInner(alloc, opts, stdout);
+ try stdout_writer.end();
+ return result;
+}
+
+fn runInner(
+ alloc: std.mem.Allocator,
+ opts: Options,
+ stdout: *std.Io.Writer,
+) !u8 {
+ var cfg = try Config.default(alloc);
+ defer cfg.deinit();
+
+ // If a config path is passed, validate it, otherwise validate default configs
+ if (opts.@"config-file") |config_path| {
+ var buf: [std.fs.max_path_bytes]u8 = undefined;
+ const abs_path = try std.fs.cwd().realpath(config_path, &buf);
+ try cfg.loadFile(alloc, abs_path);
+ try cfg.loadRecursiveFiles(alloc);
+ } else {
+ cfg = try Config.load(alloc);
+ }
+
+ try cfg.finalize();
+
+ if (cfg._diagnostics.items().len > 0) {
+ for (cfg._diagnostics.items()) |diag| {
+ try stdout.print("{f}\n", .{diag});
+ }
+ return 1;
+ }
+
+ return 0;
+}