diff options
Diffstat (limited to 'src/cmd/path.zig')
-rw-r--r-- | src/cmd/path.zig | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/cmd/path.zig b/src/cmd/path.zig index f8d5939..baf1c2e 100644 --- a/src/cmd/path.zig +++ b/src/cmd/path.zig @@ -4,19 +4,18 @@ const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; -const OutputCapture = types.OutputCapture; -const InputSource = types.InputSource; +const CommandContext = types.CommandContext; pub const PathGet = struct { - pub fn eval(path_get: PathGet, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + pub fn eval(path_get: PathGet, ctx: CommandContext) !CommandStatus { _ = path_get; - _ = input_source; + _ = ctx.input_source; - const current_path = std.process.getEnvVarOwned(allocator, "PATH") catch |err| switch (err) { + const current_path = std.process.getEnvVarOwned(ctx.allocator, "PATH") catch |err| switch (err) { error.EnvironmentVariableNotFound => { // PATH not set, show empty const output = "PATH=(not set)\n"; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); @@ -25,7 +24,7 @@ pub const PathGet = struct { }, else => { const error_msg = "Cannot access PATH environment variable\n"; - if (output_capture) |capture| { + if (ctx.output_capture) |capture| { try capture.write(error_msg); } else { print("{s}", .{error_msg}); @@ -33,11 +32,11 @@ pub const PathGet = struct { return CommandStatus{ .Code = 1 }; }, }; - defer allocator.free(current_path); + defer ctx.allocator.free(current_path); - const output = try std.fmt.allocPrint(allocator, "PATH={s}\n", .{current_path}); - defer allocator.free(output); - if (output_capture) |capture| { + 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}); @@ -49,15 +48,15 @@ pub const PathGet = struct { pub const PathSet = struct { value: []const u8, - pub fn eval(path_set: PathSet, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { - _ = input_source; + pub fn eval(path_set: PathSet, ctx: CommandContext) !CommandStatus { + _ = ctx.input_source; // Note: In a real DOS system, this would persist for the session // Here we just show what would be set but don't actually set it // since Zig's std.process doesn't provide a simple way to set env vars - const output = try std.fmt.allocPrint(allocator, "PATH would be set to: {s}\n(Note: Environment variable setting not implemented in this shell)\n", .{path_set.value}); - defer allocator.free(output); - if (output_capture) |capture| { + 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}); |