diff options
Diffstat (limited to 'src/cmd/remove.zig')
-rw-r--r-- | src/cmd/remove.zig | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cmd/remove.zig b/src/cmd/remove.zig new file mode 100644 index 0000000..91acf31 --- /dev/null +++ b/src/cmd/remove.zig @@ -0,0 +1,50 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const print = std.debug.print; + +const types = @import("./types.zig"); +const CommandStatus = types.CommandStatus; +const OutputCapture = types.OutputCapture; +const InputSource = types.InputSource; + +pub const Remove = struct { + path: []const u8, + + pub fn eval(remove: Remove, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + _ = allocator; + _ = input_source; + + const file_path = remove.path; + + // Check for wildcards (basic support) + if (std.mem.indexOf(u8, file_path, "*") != null or std.mem.indexOf(u8, file_path, "?") != null) { + // Simple wildcard deletion - just show error for now + const error_msg = "Wildcard deletion not yet implemented\n"; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + } + + // Delete single file + std.fs.cwd().deleteFile(file_path) catch |err| { + const error_msg = switch (err) { + error.FileNotFound => "File not found\n", + error.AccessDenied => "Access denied\n", + error.IsDir => "Access denied - cannot delete directory\n", + else => "Cannot delete file\n", + }; + if (output_capture) |capture| { + try capture.write(error_msg); + } else { + print("{s}", .{error_msg}); + } + return CommandStatus{ .Code = 1 }; + }; + + // No output for successful deletion (DOS style) + return CommandStatus{ .Code = 0 }; + } +}; |