summaryrefslogtreecommitdiff
path: root/src/cmd/chdir.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/chdir.zig')
-rw-r--r--src/cmd/chdir.zig43
1 files changed, 12 insertions, 31 deletions
diff --git a/src/cmd/chdir.zig b/src/cmd/chdir.zig
index e2895bf..1adfdd8 100644
--- a/src/cmd/chdir.zig
+++ b/src/cmd/chdir.zig
@@ -1,6 +1,5 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
-const print = std.debug.print;
const paths = @import("../paths.zig");
const formatDosPath = paths.formatDosPath;
@@ -17,11 +16,8 @@ pub const Chdir = struct {
// No arguments - display current directory
const cwd = std.fs.cwd().realpathAlloc(ctx.allocator, ".") catch {
const error_msg = "Unable to determine current directory\n";
- if (ctx.output_capture) |capture| {
- try capture.write(error_msg);
- } else {
- print("{s}", .{error_msg});
- }
+ var writer = ctx.output_writer;
+ try writer.write(error_msg);
return CommandStatus{ .Code = 1 };
};
defer ctx.allocator.free(cwd);
@@ -32,11 +28,8 @@ pub const Chdir = struct {
const output = try std.fmt.allocPrint(ctx.allocator, "{s}\n", .{formatted_path});
defer ctx.allocator.free(output);
- if (ctx.output_capture) |capture| {
- try capture.write(output);
- } else {
- print("{s}", .{output});
- }
+ var writer = ctx.output_writer;
+ try writer.write(output);
return CommandStatus{ .Code = 0 };
} else {
// Change directory
@@ -47,22 +40,16 @@ pub const Chdir = struct {
// Go to parent directory
std.process.changeCurDir("..") catch {
const error_msg = "The system cannot find the path specified.\n";
- if (ctx.output_capture) |capture| {
- try capture.write(error_msg);
- } else {
- print("{s}", .{error_msg});
- }
+ var writer = ctx.output_writer;
+ try writer.write(error_msg);
return CommandStatus{ .Code = 1 };
};
} else if (std.mem.eql(u8, target_path, "\\") or std.mem.eql(u8, target_path, "/")) {
// Go to root directory - simplified to just go to "/"
std.process.changeCurDir("/") catch {
const error_msg = "The system cannot find the path specified.\n";
- if (ctx.output_capture) |capture| {
- try capture.write(error_msg);
- } else {
- print("{s}", .{error_msg});
- }
+ var writer = ctx.output_writer;
+ try writer.write(error_msg);
return CommandStatus{ .Code = 1 };
};
} else {
@@ -71,22 +58,16 @@ pub const Chdir = struct {
for (target_path) |ch| {
if (ch == 0) {
const error_msg = "Invalid path: contains null character\n";
- if (ctx.output_capture) |capture| {
- try capture.write(error_msg);
- } else {
- print("{s}", .{error_msg});
- }
+ var writer = ctx.output_writer;
+ try writer.write(error_msg);
return CommandStatus{ .Code = 1 };
}
}
std.process.changeCurDir(target_path) catch {
const error_msg = "The system cannot find the path specified.\n";
- if (ctx.output_capture) |capture| {
- try capture.write(error_msg);
- } else {
- print("{s}", .{error_msg});
- }
+ var writer = ctx.output_writer;
+ try writer.write(error_msg);
return CommandStatus{ .Code = 1 };
};
}