diff options
Diffstat (limited to 'src/cmd/path.zig')
-rw-r--r-- | src/cmd/path.zig | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/cmd/path.zig b/src/cmd/path.zig index ca4de9a..009621f 100644 --- a/src/cmd/path.zig +++ b/src/cmd/path.zig @@ -1,6 +1,5 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; @@ -15,20 +14,14 @@ pub const PathGet = struct { error.EnvironmentVariableNotFound => { // PATH not set, show empty const output = "PATH=(not set)\n"; - 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 => { const error_msg = "Cannot access PATH environment variable\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 }; }, }; @@ -36,11 +29,8 @@ pub const PathGet = struct { const output = try std.fmt.allocPrint(ctx.allocator, "PATH={s}\n", .{current_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 }; } }; @@ -54,11 +44,8 @@ pub const PathSet = struct { // since Zig's std.process doesn't provide a simple way to set env vars const output = try std.fmt.allocPrint(ctx.allocator, "PATH would be set to: {s}\n(Note: Environment variable setting not implemented in this shell)\n", .{path_set.value}); 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 }; } }; |