From b3461229a297f9d3160560dbd87542b9eacbc481 Mon Sep 17 00:00:00 2001 From: iddev5 Date: Sun, 21 Nov 2021 23:16:39 +0530 Subject: [PATCH] Improve ``zigup default`` and ``zigup list`` output Default command now also points to the actual directory if default compiler is master. List command now also marks which one is the master also also marks the default compiler with an asterisk. --- zigup.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/zigup.zig b/zigup.zig index 1c40168..32c04aa 100644 --- a/zigup.zig +++ b/zigup.zig @@ -461,6 +461,12 @@ 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); + const stdout = std.io.getStdOut().writer(); { var it = install_dir.iterate(); @@ -469,7 +475,24 @@ 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}); + + const is_master = if (master_dir) |master| + (if (mem.eql(u8, master, entry.name)) true else false) + else false; + + if (is_master) { + try stdout.writeAll(" -> master"); + } + + if (default_compiler) |default| { + if (mem.eql(u8, default, entry.name) or (is_master and mem.eql(u8, default, "master"))) { + try stdout.writeAll(" [*]"); + } + } + + try stdout.writeByte('\n'); } } } @@ -613,7 +636,26 @@ 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}); + if (mem.eql(u8, default_compiler, "master")) { + 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); + + if (master_dir) |master| { + try stdout.print("master -> {s}\n", .{master}); + } + } + else { + try stdout.print("{s}\n", .{default_compiler}); + } } else { try stdout.writeAll("\n"); }