diff options
author | makefunstuff <[email protected]> | 2024-07-03 01:46:54 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-03 01:46:54 +0200 |
commit | 389197eef38182b3610a881399d9d04c6cf59f72 (patch) | |
tree | e28d24ac215babdc7e0c3fb3efb5b625566d73ed | |
parent | 227d41bbf89ae6401fdbbe536fc67d3bb908ee64 (diff) | |
download | tinkerbunk-389197eef38182b3610a881399d9d04c6cf59f72.tar.gz |
kinda works
Diffstat (limited to '')
-rw-r--r-- | src/main.zig | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/main.zig b/src/main.zig index 522eb43..653dd3b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,7 +3,16 @@ const ls = @import("ls.zig"); const socket_server = @import("socket-server.zig"); const sdl_window = @import("sdl-window.zig"); -const commands = [_]u8{ "ls", "tcp", "window", "brr" }; +const commands = [_]struct { + name: []const u8, + command: Command, +}{ + .{ .name = "ls", .command = Command.LS }, + .{ .name = "tcp", .command = Command.TCP }, + .{ .name = "window", .command = Command.WINDOW }, + .{ .name = "brr", .command = Command.BRR }, +}; + const Command = enum { LS, TCP, @@ -15,11 +24,15 @@ const Arg = struct { const Self = @This(); name: []const u8, - command: Command, + command: Command = undefined, - fn parse(self: *Self) void { + fn parse(self: *Self) !void { inline for (commands) |command| { - if (std.mem.eql([]u8, command, self.name)) {} + if (std.mem.eql(u8, command.name, self.name)) { + self.command = command.command; + } else { + return error.CommandNotFound; + } } } }; @@ -37,7 +50,20 @@ pub fn main() !void { return; } - if (args.len == 2) {} + if (args.len == 2) { + var argument = Arg{ + .name = args[1], + }; + try argument.parse(); + switch (argument.command) { + .LS => try ls.ls(), + .TCP => try socket_server.start_server(), + .WINDOW => try sdl_window.present_sdl_window(), + else => { + return; + }, + } + } std.debug.print("Unknown command. Use 'help' for usage information.\n", .{}); print_help(); |