2024-12-01 21:18:39 +01:00
|
|
|
const std = @import("std");
|
2024-12-09 22:56:38 +01:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
const eql = @import("std").mem.eql;
|
|
|
|
|
|
|
|
const stdout = std.io.getStdOut().writer();
|
2024-12-01 21:18:39 +01:00
|
|
|
|
|
|
|
pub fn main() !void {
|
2024-12-09 22:56:38 +01:00
|
|
|
// Read the first argument to determine the subcommand
|
|
|
|
const allocator = std.heap.page_allocator;
|
|
|
|
var args = try std.process.argsWithAllocator(allocator);
|
|
|
|
defer args.deinit();
|
|
|
|
|
|
|
|
_ = args.next(); // Skip the first argument, which is the program name
|
|
|
|
|
|
|
|
const firstArg = args.next() orelse {
|
|
|
|
try stdout.print("No subcommand provided\n", .{});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (eql(u8, firstArg, "list")) {
|
|
|
|
try listEntries();
|
|
|
|
} else if (eql(u8, firstArg, "create")) {
|
|
|
|
try createNewEntry();
|
|
|
|
} else {
|
|
|
|
try stdout.print("Unknown subcommand: {s}\n", .{firstArg});
|
2024-12-01 21:18:39 +01:00
|
|
|
}
|
2024-12-09 22:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn createNewEntry() !void {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
fn listEntries() !void {
|
|
|
|
const file = try std.fs.cwd().openFile("entries.log.gmi", .{});
|
|
|
|
defer file.close();
|
|
|
|
|
|
|
|
var bufReader = std.io.bufferedReader(file.reader());
|
|
|
|
var inStream = bufReader.reader();
|
|
|
|
|
|
|
|
var buf: [1024]u8 = undefined;
|
|
|
|
while (try inStream.readUntilDelimiterOrEof(&buf, '\n')) |line| {
|
|
|
|
try stdout.print("{s}\n", .{ line });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|