summaryrefslogtreecommitdiff
path: root/src/cmd/mkdir.zig
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-14 16:31:23 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2025-08-14 16:31:23 +0200
commitf40779cf8ebe81ffa802967587a83d71c74c1c7e (patch)
tree2728f9f8c4f90cb471478c1d0fa936ea4fc9e7cd /src/cmd/mkdir.zig
parentb74311035a816bbdf9ea69f172d7f6538d8ae9f8 (diff)
Factor out CD, DEL, MD, RD, PATH, DIR, TYPE.
Diffstat (limited to 'src/cmd/mkdir.zig')
-rw-r--r--src/cmd/mkdir.zig38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/cmd/mkdir.zig b/src/cmd/mkdir.zig
new file mode 100644
index 0000000..55d2ab6
--- /dev/null
+++ b/src/cmd/mkdir.zig
@@ -0,0 +1,38 @@
+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 Mkdir = struct {
+ path: []const u8,
+
+ pub fn eval(mkdir: Mkdir, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus {
+ _ = allocator;
+ _ = input_source;
+
+ const dir_path = mkdir.path;
+
+ std.fs.cwd().makeDir(dir_path) catch |err| {
+ const error_msg = switch (err) {
+ error.PathAlreadyExists => "A subdirectory or file already exists\n",
+ error.AccessDenied => "Access denied\n",
+ error.FileNotFound => "The system cannot find the path specified\n",
+ error.NotDir => "The system cannot find the path specified\n",
+ else => "Unable to create directory\n",
+ };
+ if (output_capture) |capture| {
+ try capture.write(error_msg);
+ } else {
+ print("{s}", .{error_msg});
+ }
+ return CommandStatus{ .Code = 1 };
+ };
+
+ // No output for successful creation (DOS style)
+ return CommandStatus{ .Code = 0 };
+ }
+};