const std = @import("std"); const xdg = @import("xdg"); const zup = @import("zup"); const Allocator = std.mem.Allocator; const Installation = zup.Installation; pub const params = ""; pub const description = "Switches to a Zig version. Run `zup list -i` to see installed s."; pub const min_args = 1; pub const max_args = 1; pub fn main(comptime Result: type, allocator: Allocator, res: Result) !void { const name = res.positionals[0]; if (!try Installation.isInstalled(allocator, name)) { std.log.err( "No installation by name {s} found, run `zup install {s}`", .{ name, name }, ); return error.InstallationNotFound; } const target = blk: { const data_home = try xdg.getDataHome(allocator, "zup"); defer allocator.free(data_home); break :blk try std.fs.path.join(allocator, &.{ data_home, name, "zig" }); }; defer allocator.free(target); var bin_home = try xdg.openBinHome(allocator); defer bin_home.close(); bin_home.deleteFile("zig") catch {}; try bin_home.symLink(target, "zig", .{}); std.log.info("Switched to {s}", .{name}); }