const std = @import("std"); const Allocator = std.mem.Allocator; const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; const CommandContext = types.CommandContext; pub const PathGet = struct { pub fn eval(path_get: PathGet, ctx: CommandContext) !CommandStatus { _ = path_get; _ = ctx.input_source; 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 (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{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}); } return CommandStatus{ .Code = 1 }; }, }; defer ctx.allocator.free(current_path); 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}); } return CommandStatus{ .Code = 0 }; } }; pub const PathSet = struct { value: []const u8, pub fn eval(path_set: PathSet, ctx: CommandContext) !CommandStatus { // 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(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}); } return CommandStatus{ .Code = 0 }; } };