Source
pub fn addUserInputOption(b: *Build, name_raw: []const u8, value_raw: []const u8) error{OutOfMemory}!bool {
const name = b.dupe(name_raw);
const value = b.dupe(value_raw);
const gop = try b.user_input_options.getOrPut(name);
if (!gop.found_existing) {
gop.value_ptr.* = UserInputOption{
.name = name,
.value = .{ .scalar = value },
.used = false,
};
return false;
}
// option already exists
switch (gop.value_ptr.value) {
.scalar => |s| {
// turn it into a list
var list = ArrayList([]const u8).init(b.allocator);
try list.append(s);
try list.append(value);
try b.user_input_options.put(name, .{
.name = name,
.value = .{ .list = list },
.used = false,
});
},
.list => |*list| {
// append to the list
try list.append(value);
try b.user_input_options.put(name, .{
.name = name,
.value = .{ .list = list.* },
.used = false,
});
},
.flag => {
log.warn("option '-D{s}={s}' conflicts with flag '-D{s}'.", .{ name, value, name });
return true;
},
.map => |*map| {
_ = map;
log.warn("TODO maps as command line arguments is not implemented yet.", .{});
return true;
},
.lazy_path, .lazy_path_list => {
log.warn("the lazy path value type isn't added from the CLI, but somehow '{s}' is a .{}", .{ name, std.zig.fmtId(@tagName(gop.value_ptr.value)) });
return true;
},
}
return false;
}