Support default string values
For properties of type string, allow a default value to be set for the
property on the interface. This provides the ability to have a default
value to an intended free-form string instead of using enumerated
values.
Tested:
Verified generated interface object initializes a string property
to a default value
Only properties of type string with a default defined are initialized
with the given default value as a string
Change-Id: I1e75dff1c26a4a872e9e3e7959106470c32c9be7
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index 83d9f3a..661bce4 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -11,11 +11,15 @@
self.flags = kwargs.pop('flags', [])
self.errors = kwargs.pop('errors', [])
- # Convert True/False to 'true'/'false'
- # because it will be rendered as C++ code
- if (self.defaultValue is not None and
- isinstance(self.defaultValue, bool)):
- self.defaultValue = 'true' if self.defaultValue else 'false'
+ if (self.defaultValue is not None):
+ if (isinstance(self.defaultValue, bool)):
+ # Convert True/False to 'true'/'false'
+ # because it will be rendered as C++ code
+ self.defaultValue = 'true' if self.defaultValue else 'false'
+ elif(isinstance(self.defaultValue, str) and
+ self.typeName.lower() == "string"):
+ # Wrap string type default values with double-quotes
+ self.defaultValue = "\"" + self.defaultValue + "\""
super(Property, self).__init__(**kwargs)