Skip to content

Lightpanda: the headless browser designed for AI and automation

Merge branch 'main' into shell-completion

Adrià Arrufat79e0a111ad03
diff --cc src/Config.zig
index 5f354d61b,21dc0c5fb..6cd08764d
--- a/src/Config.zig
+++ b/src/Config.zig
@@@ -1139,11 -1142,11 +1151,11 @@@ pub fn printUsageAndExit(self: *const C
\\{s}
\\
, .{ @field(Help, @tagName(tag)), Help.common_options });
- break :text try std.fmt.allocPrint(allocator, template, .{ exec_name, info_or_warn, pretty_or_logfmt });
+ break :text try allocator.print(template, .{ exec_name, info_or_warn, pretty_or_logfmt });
},
- .version => text: {
- const template = Help.version ++ "\n";
+ inline .version, .completion => |tag| text: {
+ const template = @field(Help, @tagName(tag)) ++ "\n";
- break :text try std.fmt.allocPrint(allocator, template, .{exec_name});
+ break :text try allocator.print(template, .{exec_name});
},
};
defer allocator.free(text);
diff --cc src/cli.zig
index 2bd03e566,cd4641419..2821e6042
--- a/src/cli.zig
+++ b/src/cli.zig
@@@ -194,12 -190,11 +194,15 @@@ const string = @import("string.zig")
/// .help => |tag| printHelp(tag),
/// }
/// ```
+/// Tag names of an enum, or field names of a (packed) struct option.
pub fn tagNames(comptime E: type) []const []const u8 {
return comptime blk: {
- const fields = std.meta.fields(E);
- var names: [fields.len][]const u8 = undefined;
- for (fields, &names) |f, *n| n.* = f.name;
- const field_names = @typeInfo(E).@"enum".field_names;
++ const field_names = switch (@typeInfo(E)) {
++ inline .@"enum", .@"struct" => |info| info.field_names,
++ else => @compileError("expected an enum or struct"),
++ };
+ var names: [field_names.len][]const u8 = undefined;
+ for (field_names, &names) |field_name, *n| n.* = field_name;
const frozen = names;
break :blk &frozen;
};
@@@ -277,11 -241,17 +280,17 @@@ pub fn Builder(comptime commands: anyty
break :blk @Enum(Tag, .exhaustive, &names, &std.simd.iota(Tag, len));
};
- const command_names = tagNames(Enum);
+ pub const command_names = tagNames(Enum);
- /// Creates an array of `StructField` out of given options.
- fn optionsToStructFields(comptime options: anytype) [options.len]std.builtin.Type.StructField {
- var fields: [options.len]std.builtin.Type.StructField = undefined;
+ const Field = struct {
+ name: [:0]const u8,
+ type: type,
+ attrs: std.lang.Type.Struct.FieldAttributes,
+ };
+
+ /// Creates an array of `Field` out of given options.
+ fn optionsToFields(comptime options: anytype) [options.len]Field {
+ var fields: [options.len]Field = undefined;
inline for (options, 0..) |option, j| {
// Whether prefer `ArrayList` for the option.