diff --git a/args.zig b/args.zig index c0d260c..ef29b7f 100644 --- a/args.zig +++ b/args.zig @@ -122,7 +122,7 @@ fn requiresArg(comptime T: type) bool { return true; return switch (@as(std.builtin.TypeId, @typeInfo(Type))) { - .Int, .Float => true, + .Int, .Float, .Enum => true, .Bool => false, else => @compileError(@typeName(Type) ++ " is not a supported argument type!"), }; @@ -148,6 +148,7 @@ fn convertArgumentValue(comptime T: type, textInput: []const u8) !T { else try std.fmt.parseUnsigned(T, textInput, 10), .Float => return try std.fmt.parseFloat(T, textInput), + .Enum => return std.meta.stringToEnum(T, textInput) orelse return error.InvalidEnumeration, else => @compileError(@typeName(T) ++ " is not a supported argument type!"), } } diff --git a/demo.zig b/demo.zig index 5ae852d..e049762 100644 --- a/demo.zig +++ b/demo.zig @@ -19,6 +19,7 @@ pub fn main() !void { @"with-hexdump": bool = false, @"intermix-source": bool = false, numberOfBytes: ?i32 = null, + mode: enum { default, special, slow, fast } = .default, // This declares short-hand options for single hyphen pub const shorthands = .{