summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-12-24 10:31:03 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-12-24 10:31:03 +0100
commite125e98b53f59fe0bd3adad16ed77fd94797f0bf (patch)
tree8840c5735aab8dc967be44eb29fe5750b904790b
parent86e482838cd50eb5aac6d58209a59c6917722be4 (diff)
Add a comment to a new entry if there is a list of valid values
-rw-r--r--lesana/collection.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index e428ae1..f877d31 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -71,6 +71,23 @@ class Entry(object):
"Not adding comments because they are not"
"supported by the yaml loader."
)
+ valid_values = field.field.get('values', [])
+ if valid_values:
+ comment = "# {name} ({type}): {valid_values}".format(
+ valid_values="|".join(valid_values),
+ **field.field
+ )
+ try:
+ data.yaml_set_comment_before_after_key(
+ key=name,
+ before=comment,
+ indent=0
+ )
+ except AttributeError:
+ logger.warning(
+ "Not adding comments because they are not"
+ "supported by the yaml loader."
+ )
return data
@property