blob: 8cf52b324ee99015e4689d003c4cdf4964cca10f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
const std = @import("std");
const Allocator = std.mem.Allocator;
const types = @import("./lib/types.zig");
const CommandStatus = types.CommandStatus;
const CommandContext = types.CommandContext;
pub const Remove = struct {
path: []const u8,
pub fn eval(remove: Remove, ctx: CommandContext) !CommandStatus {
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";
var writer = ctx.output_writer;
try writer.write(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",
};
var writer = ctx.output_writer;
try writer.write(error_msg);
return CommandStatus{ .Code = 1 };
};
// No output for successful deletion (DOS style)
return CommandStatus{ .Code = 0 };
}
};
|