Adds support for enumeration items, resolves #2.
This commit is contained in:
parent
430e9e1155
commit
55fb4c6c8e
3
args.zig
3
args.zig
|
@ -122,7 +122,7 @@ fn requiresArg(comptime T: type) bool {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return switch (@as(std.builtin.TypeId, @typeInfo(Type))) {
|
return switch (@as(std.builtin.TypeId, @typeInfo(Type))) {
|
||||||
.Int, .Float => true,
|
.Int, .Float, .Enum => true,
|
||||||
.Bool => false,
|
.Bool => false,
|
||||||
else => @compileError(@typeName(Type) ++ " is not a supported argument type!"),
|
else => @compileError(@typeName(Type) ++ " is not a supported argument type!"),
|
||||||
};
|
};
|
||||||
|
@ -148,6 +148,7 @@ fn convertArgumentValue(comptime T: type, textInput: []const u8) !T {
|
||||||
else
|
else
|
||||||
try std.fmt.parseUnsigned(T, textInput, 10),
|
try std.fmt.parseUnsigned(T, textInput, 10),
|
||||||
.Float => return try std.fmt.parseFloat(T, textInput),
|
.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!"),
|
else => @compileError(@typeName(T) ++ " is not a supported argument type!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
demo.zig
1
demo.zig
|
@ -19,6 +19,7 @@ pub fn main() !void {
|
||||||
@"with-hexdump": bool = false,
|
@"with-hexdump": bool = false,
|
||||||
@"intermix-source": bool = false,
|
@"intermix-source": bool = false,
|
||||||
numberOfBytes: ?i32 = null,
|
numberOfBytes: ?i32 = null,
|
||||||
|
mode: enum { default, special, slow, fast } = .default,
|
||||||
|
|
||||||
// This declares short-hand options for single hyphen
|
// This declares short-hand options for single hyphen
|
||||||
pub const shorthands = .{
|
pub const shorthands = .{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user