From e125e98b53f59fe0bd3adad16ed77fd94797f0bf Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 24 Dec 2021 10:31:03 +0100 Subject: Add a comment to a new entry if there is a list of valid values --- lesana/collection.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 -- cgit v1.2.3