about summary refs log tree commit diff
path: root/src/main.zig
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2026-01-29 20:45:48 +0100
committerRobert Günzler <r@gnzler.io>2026-01-29 21:38:25 +0100
commitb512bd5a8b2de977c2191a21bfafaf54c0be70b4 (patch)
treeaacdfd792fe2dbf9f4cf0d87ab742b1762cd337a /src/main.zig
parent380931bc9588268fa09485be863d2fd3806f8f0d (diff)
downloadsite-b512bd5a8b2de977c2191a21bfafaf54c0be70b4.tar.gz
enable auto-commit of changes
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rw-r--r--src/main.zig35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig
index d7cb0c4..f47bd36 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -144,17 +144,17 @@ const Cli = struct {
         _ = argv.skip(); // skip arg0
 
         if (argv.inner.count == 1) {
-            try Cli.mdCmd(ctx);
-            try Cli.genCmd(ctx);
+            try Cli.mdCmd(ctx, null);
+            try Cli.genCmd(ctx, null);
         }
 
         while (argv.next()) |arg| {
             if (std.mem.eql(u8, arg, "help")) {
                 Cli.helpCmd(ctx);
             } else if (std.mem.eql(u8, arg, "gen")) {
-                try Cli.genCmd(ctx);
+                try Cli.genCmd(ctx, &argv);
             } else if (std.mem.eql(u8, arg, "md")) {
-                try Cli.mdCmd(ctx);
+                try Cli.mdCmd(ctx, &argv);
             } else if (std.mem.eql(u8, arg, "watch")) {
                 try Cli.watchCmd(ctx);
             } else if (std.mem.eql(u8, arg, "serve")) {
@@ -165,25 +165,46 @@ const Cli = struct {
         }
     }
 
+    fn checkOpts(maybe_argv: ?*std.process.ArgIterator, opts: []const []const u8) bool {
+        if (maybe_argv) |argv| {
+            const arg = argv.next() orelse return false;
+            // check opts
+            for (opts) |opt| {
+                if (std.mem.eql(u8, arg, opt)) return true;
+            }
+            // rewind argv
+            argv.*.inner.index -= 1;
+            return false;
+        } else {
+            return false;
+        }
+    }
+
     fn helpCmd(_: *Context) void {
         std.debug.print("usage: rbl [gen|md|watch|serve]\n\n", .{});
     }
 
-    fn genCmd(ctx: *Context) !void {
+    fn genCmd(ctx: *Context, argv: ?*std.process.ArgIterator) !void {
         try index(ctx);
         try gen.generate(ctx);
+
+        if (checkOpts(argv, &.{ "-c", "--commit" }))
+            try exe.commit(ctx, ctx.generated.items);
     }
 
-    fn mdCmd(ctx: *Context) !void {
+    fn mdCmd(ctx: *Context, argv: ?*std.process.ArgIterator) !void {
         try index(ctx);
         try exe.runPandoc(ctx);
+
+        if (checkOpts(argv, &.{ "-c", "--commit" }))
+            try exe.commit(ctx, ctx.generated.items);
     }
 
     fn watchCmd(ctx: *Context) !void {
         const selfExe = try std.fs.selfExePathAlloc(ctx.allocator());
         const command = try std.fmt.allocPrint(ctx.allocator(),
             \\find ./src/inc/ -type f -print | entr -nc -dd -- {s} md gen
-            , .{selfExe});
+        , .{selfExe});
 
         try exe.shell(ctx, command, null);
     }