command: coerce field names to null-terminated strings

ziglang/zig@a02bd81760 changed
builtin.StructField to necessitate this, but this should also be
backwards compatible since these should decay to plain slices just
fine.
This commit is contained in:
torque 2024-01-15 22:42:26 -08:00
parent 03a4404a17
commit b77a1f59c2
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -372,7 +372,9 @@ pub fn CommandBuilder(comptime UserContext: type) type {
// global tags and env_vars would conflict, which is less common. // global tags and env_vars would conflict, which is less common.
if (param.short_tag) |short| if (param.short_tag) |short|
tag_fields = tag_fields ++ &[_]StructField{.{ tag_fields = tag_fields ++ &[_]StructField{.{
.name = short, // this goofy construct coerces the comptime []const u8 to
// [:0]const u8.
.name = short ++ "",
.type = void, .type = void,
.default_value = null, .default_value = null,
.is_comptime = false, .is_comptime = false,
@ -381,7 +383,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
if (param.long_tag) |long| if (param.long_tag) |long|
tag_fields = tag_fields ++ &[_]StructField{.{ tag_fields = tag_fields ++ &[_]StructField{.{
.name = long, .name = long ++ "",
.type = void, .type = void,
.default_value = null, .default_value = null,
.is_comptime = false, .is_comptime = false,
@ -390,7 +392,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
if (param.env_var) |env_var| if (param.env_var) |env_var|
env_var_fields = env_var_fields ++ &[_]StructField{.{ env_var_fields = env_var_fields ++ &[_]StructField{.{
.name = env_var, .name = env_var ++ "",
.type = void, .type = void,
.default_value = null, .default_value = null,
.is_comptime = false, .is_comptime = false,
@ -435,7 +437,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
const default = if (param.default) |def| &@as(FieldType, def) else @as(?*const anyopaque, null); const default = if (param.default) |def| &@as(FieldType, def) else @as(?*const anyopaque, null);
fields = fields ++ &[_]StructField{.{ fields = fields ++ &[_]StructField{.{
.name = param.name, .name = param.name ++ "",
.type = FieldType, .type = FieldType,
.default_value = @ptrCast(default), .default_value = @ptrCast(default),
.is_comptime = false, .is_comptime = false,
@ -505,7 +507,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
?PType.G.IntermediateType(); ?PType.G.IntermediateType();
fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{ fields = &(@as([fields.len]StructField, fields[0..fields.len].*) ++ [1]StructField{.{
.name = param.name, .name = param.name ++ "",
.type = FieldType, .type = FieldType,
.default_value = @ptrCast(&@as( .default_value = @ptrCast(&@as(
FieldType, FieldType,