blob: ad1a610ae4e050db18550e8649d10e84bcf3bc70 (
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
37
38
39
40
41
42
43
44
45
|
const std = @import("std");
const xdg = @import("xdg");
const zup = @import("zup");
const Allocator = std.mem.Allocator;
const Installation = zup.Installation;
pub const params =
\\-f, --force Remove even if it is the active installation
\\<NAME>
;
pub const description = "Removes an installed Zig version. Run `zup list -i` to see installed <NAME>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("{s} is not installed!", .{name});
return error.InstallationNotFound;
}
const is_active = try Installation.isActive(allocator, name);
if (is_active and !res.args.force) {
std.log.err("{s} is the active installation, not removing without --force!", .{name});
return error.CantRemove;
}
var data_home = try xdg.openDataHome(allocator, "zup");
defer data_home.close();
std.log.info("Removing {s}...", .{name});
try data_home.deleteTree(name);
if (is_active) {
var bin_home = try xdg.openBinHome(allocator);
defer bin_home.close();
try bin_home.deleteFile("zig");
}
std.log.info("Done", .{});
}
|