mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
cdp.lp: use enum for getSemanticTree format param
Leverages std.json.parse to automatically validate the format param into a type-safe enum.
This commit is contained in:
@@ -44,7 +44,7 @@ pub fn processMessage(cmd: anytype) !void {
|
||||
|
||||
fn getSemanticTree(cmd: anytype) !void {
|
||||
const Params = struct {
|
||||
format: ?[]const u8 = null,
|
||||
format: ?enum { text } = null,
|
||||
prune: ?bool = null,
|
||||
};
|
||||
const params = (try cmd.params(Params)) orelse Params{};
|
||||
@@ -62,8 +62,8 @@ fn getSemanticTree(cmd: anytype) !void {
|
||||
};
|
||||
|
||||
if (params.format) |format| {
|
||||
if (std.mem.eql(u8, format, "text")) {
|
||||
st.prune = params.prune orelse true; // text format defaults to pruned
|
||||
if (format == .text) {
|
||||
st.prune = params.prune orelse true;
|
||||
var aw: std.Io.Writer.Allocating = .init(cmd.arena);
|
||||
defer aw.deinit();
|
||||
try st.textStringify(&aw.writer);
|
||||
|
||||
Reference in New Issue
Block a user