diff options
Diffstat (limited to 'src/update.zig')
| -rw-r--r-- | src/update.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/update.zig b/src/update.zig new file mode 100644 index 0000000..a8fd075 --- /dev/null +++ b/src/update.zig | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | const zup = @import("zup"); | ||
| 3 | |||
| 4 | const Allocator = std.mem.Allocator; | ||
| 5 | const Installation = zup.Installation; | ||
| 6 | |||
| 7 | // TODO: A way to specify a subset? | ||
| 8 | |||
| 9 | pub const params = ""; | ||
| 10 | pub const description = "Updates all installed Zig versions."; | ||
| 11 | pub const min_args = 0; | ||
| 12 | pub const max_args = 0; | ||
| 13 | |||
| 14 | pub fn main(comptime Result: type, allocator: Allocator, _: Result) !void { | ||
| 15 | var installed = try Installation.getInstalledList(allocator); | ||
| 16 | defer Installation.deinitMap(allocator, &installed); | ||
| 17 | |||
| 18 | var available = try Installation.getAvailableList(allocator); | ||
| 19 | defer Installation.deinitMap(allocator, &available); | ||
| 20 | |||
| 21 | var it = installed.iterator(); | ||
| 22 | while (it.next()) |kv| { | ||
| 23 | const name = kv.key_ptr.*; | ||
| 24 | const inst = kv.value_ptr.*; | ||
| 25 | if (available.get(name)) |avail| { | ||
| 26 | if (avail.version.order(inst.version) == .gt) { | ||
| 27 | std.log.info("Updating {s} from {} to {}...", .{ name, inst.version, avail.version }); | ||
| 28 | try zup.install.base.perform(allocator, name, true, available); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | std.log.info("Done updating", .{}); | ||
| 34 | } | ||