2023-09-13 00:11:45 -07:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
const noclip = @import("noclip");
|
|
|
|
|
|
|
|
const config = @import("./config.zig");
|
|
|
|
|
|
|
|
const scribe_cmd = cmd: {
|
|
|
|
var builder = noclip.CommandBuilder(*const std.mem.Allocator){
|
|
|
|
.description =
|
|
|
|
\\consume lore files and produce rendered output
|
|
|
|
\\
|
|
|
|
\\
|
|
|
|
,
|
|
|
|
};
|
2023-09-14 23:38:24 -07:00
|
|
|
builder.stringArgument(.{
|
|
|
|
.name = "input",
|
|
|
|
.description = "document to parse",
|
|
|
|
});
|
2023-09-13 00:11:45 -07:00
|
|
|
|
|
|
|
break :cmd builder;
|
|
|
|
};
|
|
|
|
|
2023-09-14 23:38:24 -07:00
|
|
|
pub fn scribe(alloc: *const std.mem.Allocator, options: scribe_cmd.Output()) !void {
|
|
|
|
const buffa = try std.fs.cwd().readFileAlloc(alloc.*, options.input, 4_294_967_295);
|
|
|
|
defer alloc.free(buffa);
|
2023-09-13 00:11:45 -07:00
|
|
|
|
2023-09-14 23:38:24 -07:00
|
|
|
var parser = config.Parser{
|
|
|
|
.allocator = alloc.*,
|
|
|
|
// .dupe_behavior = .use_last,
|
|
|
|
};
|
|
|
|
|
|
|
|
const document = try parser.parseBuffer(buffa);
|
|
|
|
defer document.deinit();
|
|
|
|
document.printDebug();
|
2023-09-13 00:11:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn run(alloc: std.mem.Allocator) !void {
|
|
|
|
const base = try noclip.commandGroup(alloc, .{
|
|
|
|
.description =
|
|
|
|
\\produce and manipulate collections of lore
|
|
|
|
\\
|
|
|
|
,
|
|
|
|
});
|
|
|
|
defer base.deinitTree();
|
|
|
|
|
|
|
|
try base.addSubcommand("scribe", try scribe_cmd.createInterface(alloc, scribe, &alloc));
|
|
|
|
|
|
|
|
try base.execute();
|
|
|
|
}
|