~gpanders/wk

ref: 40ec79b40050caf014bb0be59391fd4d5843dab5 wk/src/cmd/backlinks.zig -rw-r--r-- 820 bytes
40ec79b4 — Greg Anders Remove modified logic 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const std = @import("std");
const fmt = std.fmt;
const mem = std.mem;
const stdout = std.io.getStdOut().outStream();

const Command = @import("../cmd.zig").Command;
const Zettel = @import("../zettel.zig").Zettel;
const getZettels = @import("../zettel.zig").getZettels;
const updateBacklinks = @import("../zettel.zig").updateBacklinks;

pub const cmd = Command{
    .name = "backlinks",
    .aliases = &[_][]const u8{"bl"},
    .usage = "bl|backlinks [NOTE [NOTE ..]]",
    .desc = "Add backlinks to given notes (all notes if no argument given).",
    .run = run,
};

pub fn run(allocator: *mem.Allocator, args: ?[]const []const u8) Command.Error!void {
    const zettels = try getZettels(allocator);
    try updateBacklinks(allocator, zettels);
    stdout.print("Updated backlinks in all notes.\n", .{}) catch return;
}