Skip to content

Commit

Permalink
chore: adjust clean up msg
Browse files Browse the repository at this point in the history
  • Loading branch information
hendriknielaender committed Dec 8, 2024
1 parent 542df92 commit ba8c163
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions src/command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -475,44 +475,16 @@ fn clean_store() !void {
bytes_freed += file_size;
}

// Format bytes_freed into a human-readable format
var formatted_size: []const u8 = undefined;
if (bytes_freed > 0) {
formatted_size = try format_bytes(bytes_freed, allocator);
defer allocator.free(formatted_size); // Ensure the buffer is freed after usage
}

std.debug.print("{s} ", .{formatted_size});

if (files_removed > 0) {
try color.bold().green().print(
"Cleaned up {d} old download artifact(s), freeing {s} of space.\n",
.{ files_removed, formatted_size },
"Cleaned up {d} old download artifact(s).\n",
.{files_removed},
);
} else {
try color.bold().cyan().print("No old download artifacts found to clean.\n", .{});
}
}

/// Formats bytes into a human-readable string (e.g., KB, MB, GB)
fn format_bytes(bytes: u64, allocator: std.mem.Allocator) ![]const u8 {
const units = [_][]const u8{ "B", "KB", "MB", "GB", "TB" };
var size = bytes;
var unit_index: usize = 0;

while (size >= 1024 and unit_index < units.len - 1) : (unit_index += 1) {
size /= 1024;
}

// Allocate buffer for the formatted string
const buffer = try allocator.alloc(u8, 20);

// Format the string
_ = try std.fmt.bufPrint(buffer, "{d} {s}", .{ size, units[unit_index] });

return buffer;
}

fn get_version() !void {
comptime var color = util_color.Color.ComptimeStyle.init();
const version_message = color.cyan().fmt("zvm " ++ options.version ++ "\n");
Expand Down

0 comments on commit ba8c163

Please sign in to comment.