mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00

This fixes a regression from #2454. In that PR, we added an error when positional arguments are detected. I believe that's correct, but we were silently relying on the previous behavior in the CLI commands. This commit changes the CLI commands to use a new argsIterator function that creates an iterator that skips the first argument (argv0). This is the same behavior that the config parsing does and now uses this shared logic. This also makes it so the argsIterator ignores actions (`+things`) and we document that we expect those to be handled earlier.
54 lines
1.5 KiB
Zig
54 lines
1.5 KiB
Zig
const std = @import("std");
|
|
const args = @import("args.zig");
|
|
const Action = @import("action.zig").Action;
|
|
const Allocator = std.mem.Allocator;
|
|
const help_strings = @import("help_strings");
|
|
|
|
pub const Options = struct {
|
|
/// If `true`, print out documentation about the action associated with the
|
|
/// keybinds.
|
|
docs: bool = false,
|
|
|
|
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 `list-actions` command is used to list all the available keybind actions
|
|
/// for Ghostty.
|
|
///
|
|
/// The `--docs` argument will print out the documentation for each action.
|
|
pub fn run(alloc: Allocator) !u8 {
|
|
var opts: Options = .{};
|
|
defer opts.deinit();
|
|
|
|
{
|
|
var iter = try args.argsIterator(alloc);
|
|
defer iter.deinit();
|
|
try args.parse(Options, alloc, &opts, &iter);
|
|
}
|
|
|
|
const stdout = std.io.getStdOut().writer();
|
|
const info = @typeInfo(help_strings.KeybindAction);
|
|
inline for (info.Struct.decls) |field| {
|
|
try stdout.print("{s}", .{field.name});
|
|
if (opts.docs) {
|
|
try stdout.print(":\n", .{});
|
|
var iter = std.mem.splitScalar(u8, std.mem.trimRight(u8, @field(help_strings.KeybindAction, field.name), &std.ascii.whitespace), '\n');
|
|
while (iter.next()) |line| {
|
|
try stdout.print(" {s}\n", .{line});
|
|
}
|
|
} else {
|
|
try stdout.print("\n", .{});
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|