Fix handling of optional struct-typed command arguments in chip-tool. (#31658)
AddArgument documents that for "complex" (i.e. list and struct) arguments there
is no automatic type-based handling of optionality and the "kOptional" flag
needs to be passed in explicitly. But the generated code was not doing that.
diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt
index 37aaef2..bf981ec 100644
--- a/examples/chip-tool/templates/commands.zapt
+++ b/examples/chip-tool/templates/commands.zapt
@@ -31,7 +31,7 @@
{
{{#zcl_command_arguments}}
{{#if_chip_complex}}
- AddArgument("{{asUpperCamelCase label}}", &mComplex_{{asUpperCamelCase label}});
+ AddArgument("{{asUpperCamelCase label}}", &mComplex_{{asUpperCamelCase label}}{{#if isOptional}}, "", Argument::kOptional{{/if}});
{{else if (isString type)}}
AddArgument("{{asUpperCamelCase label}}", &mRequest.{{asLowerCamelCase label}});
{{else}}
diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h
index 854e51c..c4eb22e 100644
--- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h
+++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h
@@ -11052,10 +11052,10 @@
{
AddArgument("StartTime", 0, UINT32_MAX, &mRequest.startTime);
AddArgument("EndTime", 0, UINT32_MAX, &mRequest.endTime);
- AddArgument("ChannelList", &mComplex_ChannelList);
- AddArgument("PageToken", &mComplex_PageToken);
+ AddArgument("ChannelList", &mComplex_ChannelList, "", Argument::kOptional);
+ AddArgument("PageToken", &mComplex_PageToken, "", Argument::kOptional);
AddArgument("RecordingFlag", 0, UINT32_MAX, &mRequest.recordingFlag);
- AddArgument("ExternalIDList", &mComplex_ExternalIDList);
+ AddArgument("ExternalIDList", &mComplex_ExternalIDList, "", Argument::kOptional);
AddArgument("Data", &mRequest.data);
ClusterCommand::AddArguments();
}
@@ -12103,7 +12103,7 @@
AddArgument("Search", &mComplex_Search);
AddArgument("AutoPlay", 0, 1, &mRequest.autoPlay);
AddArgument("Data", &mRequest.data);
- AddArgument("PlaybackPreferences", &mComplex_PlaybackPreferences);
+ AddArgument("PlaybackPreferences", &mComplex_PlaybackPreferences, "", Argument::kOptional);
AddArgument("UseCurrentContext", 0, 1, &mRequest.useCurrentContext);
ClusterCommand::AddArguments();
}
@@ -12147,7 +12147,7 @@
{
AddArgument("ContentURL", &mRequest.contentURL);
AddArgument("DisplayString", &mRequest.displayString);
- AddArgument("BrandingInformation", &mComplex_BrandingInformation);
+ AddArgument("BrandingInformation", &mComplex_BrandingInformation, "", Argument::kOptional);
ClusterCommand::AddArguments();
}
@@ -12303,7 +12303,7 @@
ApplicationLauncherLaunchApp(CredentialIssuerCommands * credsIssuerConfig) :
ClusterCommand("launch-app", credsIssuerConfig), mComplex_Application(&mRequest.application)
{
- AddArgument("Application", &mComplex_Application);
+ AddArgument("Application", &mComplex_Application, "", Argument::kOptional);
AddArgument("Data", &mRequest.data);
ClusterCommand::AddArguments();
}
@@ -12344,7 +12344,7 @@
ApplicationLauncherStopApp(CredentialIssuerCommands * credsIssuerConfig) :
ClusterCommand("stop-app", credsIssuerConfig), mComplex_Application(&mRequest.application)
{
- AddArgument("Application", &mComplex_Application);
+ AddArgument("Application", &mComplex_Application, "", Argument::kOptional);
ClusterCommand::AddArguments();
}
@@ -12384,7 +12384,7 @@
ApplicationLauncherHideApp(CredentialIssuerCommands * credsIssuerConfig) :
ClusterCommand("hide-app", credsIssuerConfig), mComplex_Application(&mRequest.application)
{
- AddArgument("Application", &mComplex_Application);
+ AddArgument("Application", &mComplex_Application, "", Argument::kOptional);
ClusterCommand::AddArguments();
}
@@ -14032,11 +14032,11 @@
AddArgument("OptionalString", &mRequest.optionalString);
AddArgument("NullableOptionalString", &mRequest.nullableOptionalString);
AddArgument("NullableStruct", &mComplex_NullableStruct);
- AddArgument("OptionalStruct", &mComplex_OptionalStruct);
- AddArgument("NullableOptionalStruct", &mComplex_NullableOptionalStruct);
+ AddArgument("OptionalStruct", &mComplex_OptionalStruct, "", Argument::kOptional);
+ AddArgument("NullableOptionalStruct", &mComplex_NullableOptionalStruct, "", Argument::kOptional);
AddArgument("NullableList", &mComplex_NullableList);
- AddArgument("OptionalList", &mComplex_OptionalList);
- AddArgument("NullableOptionalList", &mComplex_NullableOptionalList);
+ AddArgument("OptionalList", &mComplex_OptionalList, "", Argument::kOptional);
+ AddArgument("NullableOptionalList", &mComplex_NullableOptionalList, "", Argument::kOptional);
ClusterCommand::AddArguments();
}