summaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorJeffrey C. Ollie <jeff@ocjtech.us>2024-01-11 14:25:12 -0600
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-01-20 19:24:17 -0800
commitde428d9fe9a080ae140879c8700caaaf7ede8bbb (patch)
treee2b4c8867a16f224d0955b9ed135a391dd215fc7 /src/cli
parent8d95f514cc93cd07f94eef8b87bdecfdbc5e559d (diff)
add +show-config action to print out the config from the cli
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/action.zig5
-rw-r--r--src/cli/show_config.zig46
2 files changed, 51 insertions, 0 deletions
diff --git a/src/cli/action.zig b/src/cli/action.zig
index 2e3afb1c0..a7cbabf25 100644
--- a/src/cli/action.zig
+++ b/src/cli/action.zig
@@ -8,6 +8,7 @@ const version = @import("version.zig");
const list_keybinds = @import("list_keybinds.zig");
const list_themes = @import("list_themes.zig");
const list_colors = @import("list_colors.zig");
+const show_config = @import("show_config.zig");
/// Special commands that can be invoked via CLI flags. These are all
/// invoked by using `+<action>` as a CLI flag. The only exception is
@@ -31,6 +32,9 @@ pub const Action = enum {
/// List named RGB colors
@"list-colors",
+ /// Dump the config to stdout
+ @"show-config",
+
pub const Error = error{
/// Multiple actions were detected. You can specify at most one
/// action on the CLI otherwise the behavior desired is ambiguous.
@@ -119,6 +123,7 @@ pub const Action = enum {
.@"list-keybinds" => try list_keybinds.run(alloc),
.@"list-themes" => try list_themes.run(alloc),
.@"list-colors" => try list_colors.run(alloc),
+ .@"show-config" => try show_config.run(alloc),
};
}
diff --git a/src/cli/show_config.zig b/src/cli/show_config.zig
new file mode 100644
index 000000000..94e0dfc4e
--- /dev/null
+++ b/src/cli/show_config.zig
@@ -0,0 +1,46 @@
+const std = @import("std");
+const args = @import("args.zig");
+const Allocator = std.mem.Allocator;
+const Config = @import("../config/Config.zig");
+
+pub const Options = struct {
+ /// If true, print out the default config instead of the user's config.
+ default: bool = false,
+
+ pub fn deinit(self: Options) void {
+ _ = self;
+ }
+};
+
+/// The "show-config" command is used to list all the available configuration
+/// settings for Ghostty.
+///
+/// When executed without any arguments this will list the current settings
+/// loaded by the config file(s). If no config file is found or there aren't
+/// any changes to the settings it will print out the default ones configured
+/// for Ghostty
+///
+/// The "--default" argument will print out all the default settings
+/// configured for Ghostty
+pub fn run(alloc: Allocator) !u8 {
+ var opts: Options = .{};
+ defer opts.deinit();
+
+ {
+ var iter = try std.process.argsWithAllocator(alloc);
+ defer iter.deinit();
+ try args.parse(Options, alloc, &opts, &iter);
+ }
+
+ var config = if (opts.default) try Config.default(alloc) else try Config.load(alloc);
+ defer config.deinit();
+
+ const stdout = std.io.getStdOut().writer();
+
+ const info = @typeInfo(Config);
+ std.debug.assert(info == .Struct);
+
+ try config.formatConfig(stdout);
+
+ return 0;
+}