Refactor builtin commands dispatcher
This commit is contained in:
+9
-11
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user