Skip to content

Commit

Permalink
Update chip-tool-darwin to allow optionals in CLI (#18168)
Browse files Browse the repository at this point in the history
* Update chip-tool-darwin to set optional params in CLI

* Generated Code
  • Loading branch information
krypton36 authored and pull[bot] committed Sep 5, 2023
1 parent aea2054 commit 2210690
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 85 deletions.
34 changes: 25 additions & 9 deletions examples/chip-tool-darwin/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,30 @@ public:
{{#chip_cluster_command_arguments}}
{{#if_chip_complex}}
{{>decodable_value target=(concat "params." (asStructPropertyName label)) source=(concat "mRequest." (asStructPropertyName label)) cluster=parent.clusterName type=type depth=0}}
{{else if (isOctetString type)}}
params.{{asStructPropertyName label}} = [[NSData alloc] initWithBytes:m{{asUpperCamelCase label}}.data() length:m{{asUpperCamelCase label}}.size()];
{{else if (isOctetString type)}}
{{#if isOptional}}
if (m{{asUpperCamelCase label}}.HasValue()) {
{{/if}}
params.{{asStructPropertyName label}} = [[NSData alloc] initWithBytes:m{{asUpperCamelCase label}}{{#if isOptional}}.Value(){{/if}}.data() length:m{{asUpperCamelCase label}}{{#if isOptional}}.Value(){{/if}}.size()];
{{#if isOptional}}
}
{{/if}}
{{else if (isString type)}}
params.{{asStructPropertyName label}} = [[NSString alloc] initWithBytes:m{{asUpperCamelCase label}}.data() length:m{{asUpperCamelCase label}}.size() encoding:NSUTF8StringEncoding];
{{#if isOptional}}
if (m{{asUpperCamelCase label}}.HasValue()) {
{{/if}}
params.{{asStructPropertyName label}} = [[NSString alloc] initWithBytes:m{{asUpperCamelCase label}}{{#if isOptional}}.Value(){{/if}}.data() length:m{{asUpperCamelCase label}}{{#if isOptional}}.Value(){{/if}}.size() encoding:NSUTF8StringEncoding];
{{#if isOptional}}
}
{{/if}}
{{else}}
params.{{asStructPropertyName label}} = [NSNumber numberWith{{asObjectiveCNumberType "" type false}}:m{{asUpperCamelCase label}}];
{{#if isOptional}}
if (m{{asUpperCamelCase label}}.HasValue()) {
{{/if}}
params.{{asStructPropertyName label}} = [NSNumber numberWith{{asObjectiveCNumberType "" type false}}:m{{asUpperCamelCase label}}{{#if isOptional}}.Value(){{/if}}];
{{#if isOptional}}
}
{{/if}}
{{/if_chip_complex}}
{{/chip_cluster_command_arguments}}
uint16_t repeatCount = mRepeatCount.ValueOr(1);
Expand Down Expand Up @@ -92,12 +110,10 @@ private:
{{#if_chip_complex}}
chip::app::Clusters::{{asUpperCamelCase parent.clusterName}}::Commands::{{asUpperCamelCase parent.name}}::Type mRequest;
TypedComplexArgument<{{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}> mComplex_{{asUpperCamelCase label}};
{{else if (isOctetString type)}}
chip::ByteSpan m{{asUpperCamelCase label}};
{{else if (isCharString type)}}
chip::ByteSpan m{{asUpperCamelCase label}};
{{else if (isString type)}}
{{#if isOptional}}chip::Optional<chip::ByteSpan>{{else}}chip::ByteSpan{{/if}} m{{asUpperCamelCase label}};
{{else}}
{{chipType}} m{{asUpperCamelCase label}};
{{#if isOptional}}chip::Optional<{{chipType}}>{{else}}{{chipType}}{{/if}} m{{asUpperCamelCase label}};
{{/if_chip_complex}}
{{/chip_cluster_command_arguments}}
};
Expand Down
Loading

0 comments on commit 2210690

Please sign in to comment.