const std = @import("std"); const Allocator = std.mem.Allocator; const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; const OutputCapture = types.OutputCapture; const InputSource = types.InputSource; pub const Rmdir = struct { path: []const u8, pub fn eval(rmdir: Rmdir, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { _ = allocator; _ = input_source; const dir_path = rmdir.path; std.fs.cwd().deleteDir(dir_path) catch |err| { const error_msg = switch (err) { error.FileNotFound => "The system cannot find the path specified\n", error.AccessDenied => "Access denied\n", error.DirNotEmpty => "The directory is not empty\n", error.FileBusy => "The directory is in use\n", error.NotDir => "The system cannot find the path specified\n", else => "Unable to remove directory\n", }; if (output_capture) |capture| { try capture.write(error_msg); } else { print("{s}", .{error_msg}); } return CommandStatus{ .Code = 1 }; }; // No output for successful removal (DOS style) return CommandStatus{ .Code = 0 }; } };