about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-10-06 18:02:52 +0200
committerRobert Günzler <r@gnzler.io>2025-11-22 21:56:26 +0100
commit20ce4e9288547e8742e3664bd4c67a0a6f3224f6 (patch)
tree296617aef8321c28492c1576250928f988faff9a /src
parent67f9f8ead540b57585ff1e5d5e1457ed2152027d (diff)
downloadsite-20ce4e9288547e8742e3664bd4c67a0a6f3224f6.tar.gz
rbl: add serve command
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rw-r--r--src/exe.zig3
-rw-r--r--src/main.zig18
2 files changed, 18 insertions, 3 deletions
diff --git a/src/exe.zig b/src/exe.zig
index 56914b3..b246d56 100644
--- a/src/exe.zig
+++ b/src/exe.zig
@@ -138,7 +138,7 @@ pub fn captureStdout(ctx: *Context, argv: []const []const u8, env_map: ?*std.pro
     _ = result;
 }
 
-pub fn shell(ctx: *Context, command: []const u8) !void {
+pub fn shell(ctx: *Context, command: []const u8, env_map: ?*std.process.EnvMap) !void {
     const label = try std.fmt.allocPrint(ctx.allocator(), "running {s}", .{command});
     defer ctx.allocator().free(label);
 
@@ -152,6 +152,7 @@ pub fn shell(ctx: *Context, command: []const u8) !void {
     }, std.heap.page_allocator);
 
     p.progress_node = ctx.progress_nodes.getLast();
+    p.env_map = env_map;
 
     try p.spawn();
     const result = try p.wait();
diff --git a/src/main.zig b/src/main.zig
index 8e0b27e..7199bce 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -162,6 +162,8 @@ const Cli = struct {
                 try Cli.mdCmd(ctx);
             } else if (std.mem.eql(u8, arg, "watch")) {
                 try Cli.watchCmd(ctx);
+            } else if (std.mem.eql(u8, arg, "serve")) {
+                try Cli.serveCmd(ctx);
             } else {
                 Cli.helpCmd(ctx);
             }
@@ -169,7 +171,7 @@ const Cli = struct {
     }
 
     fn helpCmd(_: *Context) void {
-        std.debug.print("usage: rbl [gen|md]\n\n", .{});
+        std.debug.print("usage: rbl [gen|md|watch|serve]\n\n", .{});
     }
 
     fn genCmd(ctx: *Context) !void {
@@ -186,7 +188,19 @@ const Cli = struct {
     fn watchCmd(ctx: *Context) !void {
         try exe.shell(ctx,
             \\find ./src/inc/ -type f -print | entr -nc -dd -- rbl md gen
-        );
+        , null);
+    }
+
+    fn serveCmd(ctx: *Context) !void {
+        var env_map = try std.process.getEnvMap(ctx.allocator());
+        defer env_map.deinit();
+
+        try env_map.put("CADDY_HTTP_PORT", "1414");
+        try env_map.put("CADDY_HOST", "localhost");
+
+        try exe.shell(ctx,
+            \\caddy fmt --overwrite && caddy run --watch
+        , &env_map);
     }
 };