Skip to content

Commit

Permalink
Was passing key instead of value
Browse files Browse the repository at this point in the history
  • Loading branch information
BitlyTwiser committed Sep 23, 2024
1 parent fddef6d commit 49c6d64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ pub fn main() !void {
var cli = try snek(T).init(std.heap.page_allocator);
const parsed_cli = try cli.parse();

// Necessary is skipped here
// Necessary is skipped here to showcase optional values being ignored
std.debug.print("{s} {d} {any} {s} {s}", .{ parsed_cli.name, parsed_cli.location, parsed_cli.exists, parsed_cli.default_name, parsed_cli.filled_optional orelse "badvalue" });
}
8 changes: 4 additions & 4 deletions src/sneaky.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ pub fn Snek(comptime CliInterface: type) type {

switch (field_type) {
.Bool => {
@field(&interface, field.name) = try self.parseBool(serialized_arg.key);
@field(&interface, field.name) = try self.parseBool(serialized_arg.value);
},
.Int => {
@field(&interface, field.name) = try self.parseNumeric(field.type, serialized_arg.key);
@field(&interface, field.name) = try self.parseNumeric(field.type, serialized_arg.value);
},
.Float => {
@field(&interface, field.name) = try self.parseNumeric(field.type, serialized_arg.key);
@field(&interface, field.name) = try self.parseNumeric(field.type, serialized_arg.value);
},
.Pointer => {
// .Pointer is for strings since the underlying type is []const u8 which is a .Pointer type
if (field_type.Pointer.size == .Slice and field_type.Pointer.child == u8) {
// At this point, just store the string.
@field(&interface, field.name) = serialized_arg.key;
@field(&interface, field.name) = serialized_arg.value;
}
},
.Struct => {
Expand Down

0 comments on commit 49c6d64

Please sign in to comment.