diff options
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/main.zig b/src/main.zig index 197a224..93356d6 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -73,25 +73,19 @@ fn dispatch( | |||
| 73 | comptime default_fn: anytype, | 73 | comptime default_fn: anytype, |
| 74 | args: anytype, | 74 | args: anytype, |
| 75 | ) !void { | 75 | ) !void { |
| 76 | // TODO: This can still be improved, currently we're looping through all possible values, it could be somehow made | 76 | // TODO: This can still be improved, currently we're looping through all |
| 77 | // into a switch. | 77 | // possible values, it could be somehow made into a switch. |
| 78 | const cmd_enum = CommandMap.get(cmd) orelse return @call(.{}, default_fn, args); | 78 | const cmd_enum = CommandMap.get(cmd) orelse return @call(.auto, default_fn, args); |
| 79 | const commands = @typeInfo(Command).Enum.fields; | 79 | const commands = @typeInfo(Command).Enum.fields; |
| 80 | inline for (commands) |command| { | 80 | inline for (commands) |command| { |
| 81 | if (@enumToInt(cmd_enum) == command.value) { | 81 | if (@enumToInt(cmd_enum) == command.value) { |
| 82 | // TODO: zig-bug it cries about modifying a constant if | ||
| 83 | // I just write `return @call(.{}, fun, args);` | ||
| 84 | const fun = @field(@field(@This(), command.name), fn_name); | 82 | const fun = @field(@field(@This(), command.name), fn_name); |
| 85 | return call(fun, args); | 83 | return @call(.auto, fun, args); |
| 86 | } | 84 | } |
| 87 | } | 85 | } |
| 88 | unreachable; | 86 | unreachable; |
| 89 | } | 87 | } |
| 90 | 88 | ||
| 91 | inline fn call(fun: anytype, args: anytype) !void { | ||
| 92 | return @call(.{}, fun, args); | ||
| 93 | } | ||
| 94 | |||
| 95 | fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { | 89 | fn unknownCmd(cmd: []const u8, _: Config, _: *ArgIterator) !void { |
| 96 | std.log.err("Unknown subcommand: {s}", .{cmd}); | 90 | std.log.err("Unknown subcommand: {s}", .{cmd}); |
| 97 | return error.ArgError; | 91 | return error.ArgError; |