Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions zigup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ fn listCompilers(allocator: Allocator) !void {
};
defer install_dir.close();

const default_compiler = try getDefaultCompiler(allocator);
defer if (default_compiler) |default| allocator.free(default);

const master_dir = try getMasterDir(allocator, &install_dir);
defer if (master_dir) |master| allocator.free(master);

var found_default = false;

const stdout = std.io.getStdOut().writer();
{
var it = install_dir.iterate();
Expand All @@ -466,7 +474,27 @@ fn listCompilers(allocator: Allocator) !void {
continue;
if (std.mem.endsWith(u8, entry.name, ".installing"))
continue;
try stdout.print("{s}\n", .{entry.name});

try stdout.print("{s}", .{entry.name});

if (master_dir != null and mem.eql(u8, master_dir.?, entry.name)) {
try stdout.writeAll(" (master)");
}

if (default_compiler) |default| {
if (mem.eql(u8, default, entry.name)) {
try stdout.writeAll(" (default)");
found_default = true;
}
}

try stdout.writeByte('\n');
}

if (default_compiler) |default| {
if (!found_default) {
std.log.err("default compiler '{s}' is not among the installed compilers", .{default});
}
}
}
}
Expand Down Expand Up @@ -604,7 +632,27 @@ fn printDefaultCompiler(allocator: Allocator) !void {
defer if (default_compiler_opt) |default_compiler| allocator.free(default_compiler);
const stdout = std.io.getStdOut().writer();
if (default_compiler_opt) |default_compiler| {
try stdout.print("{s}\n", .{default_compiler});
const install_dir_string = try getInstallDir(allocator, .{ .create = false });
defer allocator.free(install_dir_string);

var install_dir = std.fs.openDirAbsolute(install_dir_string, .{ .iterate = true }) catch |e| switch (e) {
error.FileNotFound => return,
else => return e,
};
defer install_dir.close();

const master_dir = try getMasterDir(allocator, &install_dir);
defer if (master_dir) |master| allocator.free(master);

try stdout.print("{s}", .{default_compiler});

if (master_dir) |master| {
if (mem.eql(u8, master, default_compiler)) {
try stdout.print(" (master)", .{});
}
}

try stdout.writeByte('\n');
} else {
try stdout.writeAll("<no-default>\n");
}
Expand Down