Refactor builtin commands dispatcher

This commit is contained in:
2026-08-23 11:43:28 +03:00
parent 0548f8de26
commit 35f5d5777e
9 changed files with 78 additions and 75 deletions
+9 -11
View File
@@ -1,20 +1,18 @@
const std = @import("std");
pub fn execute(
io: std.Io,
environ: *const std.process.Environ.Map,
argv: []const []const u8,
) !void {
const path = if (argv.len >= 2)
argv[1]
const types = @import("../types.zig");
pub fn execute(ctx: types.BuiltinCommandContext) !void {
const path = if (ctx.argv.len >= 2)
ctx.argv[1]
else
environ.get("USERPROFILE") orelse environ.get("HOME") orelse {
ctx.shell.environ.get("USERPROFILE") orelse ctx.shell.environ.get("HOME") orelse {
std.debug.print("xsh: cd: cannot find home directory\n", .{});
return;
};
var dir = try std.Io.Dir.cwd().openDir(io, path, .{});
defer dir.close(io);
var dir = try std.Io.Dir.cwd().openDir(ctx.io, path, .{});
defer dir.close(ctx.io);
try std.process.setCurrentDir(io, dir);
try std.process.setCurrentDir(ctx.io, dir);
}