const std = @import("std"); const parser = @import("../shell/parser.zig"); const cd = @import("cmds/cd.zig"); const echo = @import("cmds/echo.zig"); const exit = @import("cmds/exit.zig"); const pwd = @import("cmds/pwd.zig"); const run = @import("cmds/run.zig"); const types = @import("types.zig"); const CommandFn = *const fn (types.BuiltinCommandContext) anyerror!void; const commands = std.StaticStringMap(CommandFn).initComptime(.{ .{ "cd", cd.execute }, .{ "pwd", pwd.execute }, .{ "run", run.execute }, .{ "echo", echo.execute }, .{ "exit", exit.execute }, }); pub fn execute( io: std.Io, allocator: std.mem.Allocator, shell: *types.Shell, command: parser.Command, ) !bool { if (command.argv.len == 0) return true; const name = command.argv[0]; const execute_fn = commands.get(name) orelse return false; try execute_fn(.{ .io = io, .allocator = allocator, .shell = shell, .argv = command.argv, }); return true; }