summaryrefslogtreecommitdiff
path: root/src/update.zig
blob: 6ee79517e559754e9159656497392c7d6fa879f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const std = @import("std");
const zup = @import("root");

const Config = zup.Config;
const Installation = zup.Installation;

// TODO: A way to specify a subset?

pub const params = "";
pub const description = "Updates all installed Zig versions.";
pub const min_args = 0;
pub const max_args = 0;

pub fn main(comptime Result: type, config: Config, _: Result) !void {
    const allocator = config.allocator;

    var installed = try Installation.getInstalledList(allocator);
    defer Installation.deinitMap(allocator, &installed);

    var available = try Installation.getAvailableList(config);
    defer Installation.deinitMap(allocator, &available);

    var it = installed.iterator();
    while (it.next()) |kv| {
        const name = kv.key_ptr.*;
        const inst = kv.value_ptr.*;
        if (available.get(name)) |avail| {
            if (avail.version.order(inst.version) == .gt) {
                std.log.info("Updating {s} from {f} to {f}...", .{ name, inst.version, avail.version });
                try zup.install.base.perform(allocator, name, true, available);
            }
        }
    }

    std.log.info("Done updating", .{});
}