feat: can had comments with family/variable description in examples doc

This commit is contained in:
egarette@silique.fr 2025-10-28 06:21:53 +01:00
parent 9d8be3880a
commit ecf3570b79
1024 changed files with 7043 additions and 12 deletions

View file

@ -133,6 +133,23 @@ doc:
change_default_value: true # {_('Modify values to document leaderships and dynamics families')}
comment_examples:
description: {_('Add description of variables and families when generate examples')}
default: false
disabled:
jinja: |-
{{{{ "example" not in _.contents }}}}
return_type: boolean
description: {_('disabled when example in not in contents')}
comment_column:
description: {_('Comment starts at column')}
default: 30
disabled:
variable: _.comment_examples
propertyerror: true
when: false
output_format:
description: {_('Generate document in format')}
alternative_name: do

View file

@ -87,6 +87,10 @@ class RougailOutputDoc(Examples, Changelog):
self.contents = rougailconfig["doc.contents"]
self.root = rougailconfig["doc.root"]
self.example = "example" in self.contents
if self.example:
self.comment_examples = rougailconfig["doc.comment_examples"]
if self.comment_examples:
self.comment_column = rougailconfig["doc.comment_column"]
if "variables" in self.contents:
self.with_family = not rougailconfig["doc.without_family"]
else:

View file

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from typing import Optional
from ruamel.yaml import CommentedMap
from .utils import _, calc_path
@ -57,17 +58,20 @@ class Examples: # pylint: disable=no-member,too-few-public-methods
self.examples_mandatories = examples_mandatories
def _parse_examples(self, dico, dyn_parent: Optional[str] = None) -> tuple:
examples = {}
examples_mandatories = {}
if self.comment_examples:
examples = CommentedMap()
examples_mandatories = CommentedMap()
else:
examples = {}
examples_mandatories = {}
for value in dico.values():
if value["type"] == "variable":
self._parse_examples_variable(
value, dyn_parent, examples, examples_mandatories
)
parse = self._parse_examples_variable
else:
self._parse_examples_family(
value, dyn_parent, examples, examples_mandatories
)
parse = self._parse_examples_family
parse(
value, dyn_parent, examples, examples_mandatories
)
return examples, examples_mandatories
def _parse_examples_variable(
@ -94,8 +98,18 @@ class Examples: # pylint: disable=no-member,too-few-public-methods
name = variable["names"][idx]
value = variable["example"][idx]
examples[name] = value
if self.comment_examples and "description" in variable:
description = variable["description"]
if description.endswith('.'):
description = description[:-1]
examples.yaml_add_eol_comment(description, name, column=self.comment_column)
if variable["mandatory_without_value"]:
examples_mandatories[name] = value
if self.comment_examples and "description" in variable:
description = variable["description"]
if description.endswith('.'):
description = description[:-1]
examples_mandatories.yaml_add_eol_comment(description, name, column=self.comment_column)
break
def _parse_examples_family(
@ -123,8 +137,18 @@ class Examples: # pylint: disable=no-member,too-few-public-methods
)
if ret_m:
examples_mandatories[name] = ret_m
if self.comment_examples and "description" in family["informations"]:
description = family["informations"]["description"]
if description.endswith('.'):
description = description[:-1]
examples_mandatories.yaml_add_eol_comment(description, name, column=self.comment_column)
if ret_e:
examples[name] = ret_e
if self.comment_examples and "description" in family["informations"]:
description = family["informations"]["description"]
if description.endswith('.'):
description = description[:-1]
examples.yaml_add_eol_comment(description, name, column=self.comment_column)
ori_path = family["informations"]["path"]
if "identifiers" in family["informations"]:
@ -151,16 +175,27 @@ class Examples: # pylint: disable=no-member,too-few-public-methods
if dyn_parent is not None and not path.startswith(dyn_parent):
continue
for leader_idx in range(len(leader["example"][path_idx])):
followers = {}
if self.comment_examples:
followers = CommentedMap()
else:
followers = {}
for follower in leadership.values():
if len(follower["names"]) == 1:
name = follower["names"][0]
else:
name = follower["names"][path_idx]
followers[name] = follower["example"][path_idx][leader_idx]
if self.comment_examples and "description" in follower:
description = follower["description"]
if description.endswith('.'):
description = description[:-1]
followers.yaml_add_eol_comment(description, name, column=self.comment_column)
examples.append(followers)
if leader["mandatory_without_value"]:
followers = {}
if self.comment_examples:
followers = CommentedMap()
else:
followers = {}
for follower in leadership.values():
if not follower["mandatory_without_value"]:
continue
@ -169,6 +204,11 @@ class Examples: # pylint: disable=no-member,too-few-public-methods
else:
name = follower["names"][path_idx]
followers[name] = follower["example"][path_idx][leader_idx]
if self.comment_examples and "description" in follower:
description = follower["description"]
if description.endswith('.'):
description = description[:-1]
followers.yaml_add_eol_comment(description, name, column=self.comment_column)
examples_mandatories.append(followers)
break
return examples, examples_mandatories

View file

@ -0,0 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
version: example # A variable
```
# Example with all variables modifiable
```yaml
---
version: example # A variable
```

View file

@ -0,0 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
empty: example
```
# Example with all variables modifiable
```yaml
---
empty: example
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
var1: no # A first variable
var2: # A second variable
- no
```

View file

@ -0,0 +1,13 @@
# Example with all variables modifiable
```yaml
---
var1: # A first variable
- no
- yes
- maybe
var2: # A second variable
- no
- yes
- maybe
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var2: a_value # A second variable
```

View file

@ -0,0 +1,16 @@
# Example with mandatory variables not filled in
```yaml
---
var1: # A first variable
- example.net
```
# Example with all variables modifiable
```yaml
---
var1: # A first variable
- example.net
var2: # A second variable
- example.net
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # A first variable
```
# Example with all variables modifiable
```yaml
---
var1: example # A first variable
var2: example # A second variable
```

View file

@ -0,0 +1,15 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # A first variable
var3: example # A new variable
```
# Example with all variables modifiable
```yaml
---
var1: example # A first variable
var2: example # A second variable
var3: example # A new variable
```

View file

@ -0,0 +1,16 @@
# Example with mandatory variables not filled in
```yaml
---
var1: # A first variable
- example.net
```
# Example with all variables modifiable
```yaml
---
var1: # A first variable
- example.net
var2: # A second variable
- example.net
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # A variable
var2: example # A variable
```
# Example with all variables modifiable
```yaml
---
var1: example # A variable
var2: example # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
without_type: non # A variable
```

View file

@ -0,0 +1,11 @@
# Example with all variables modifiable
```yaml
---
var1: true # The first variable
var2: true # The second variable
var3: true # The third variable
var4: false # The forth variable
var5: false # The fifth variable
var6: false # The sixth variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: true # A variable
```

View file

@ -0,0 +1,18 @@
# Example with mandatory variables not filled in
```yaml
---
var1: a_choice # The first variable
var2: a_choice # The second variable
```
# Example with all variables modifiable
```yaml
---
var1: a_choice # The first variable
var2: a_choice # The second variable
var3: a_choice # The third variable
var4: a_choice # The forth variable
var5: a # The fifth variable
var6: 1 # The sixth variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var: 9 # A variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var1: a_choice # The first variable
```
# Example with all variables modifiable
```yaml
---
var1: a_choice # The first variable
var2: a_choice # The second variable
```

View file

@ -0,0 +1,10 @@
# Example with all variables modifiable
```yaml
---
var1: # A second variable
- a
- b
- c
var2: a # A first variable
```

View file

@ -0,0 +1,11 @@
# Example with all variables modifiable
```yaml
---
var1: # A second variable
- a
- b
- c
var2: a # A first variable
var3: a # A third variable
```

View file

@ -0,0 +1,12 @@
# Example with all variables modifiable
```yaml
---
var1: # A second variable
- a
- b
- c
var2: a # A first variable
family: # family
var3: a # A third variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
custom1: xxx # The first variable
```
# Example with all variables modifiable
```yaml
---
custom1: xxx # The first variable
custom2: value # The seconf variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: my.domain.name # A domain name variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: my.domain.name # A domain name variable
```

View file

@ -0,0 +1,11 @@
# Example with all variables modifiable
```yaml
---
var1: 0.0 # The first variable
var2: 0.0 # The second variable
var3: 0.0 # The third variable
var4: 10.1 # The forth variable
var5: 10.1 # The fifth variable
var6: 10.1 # The sixth variable
```

View file

@ -0,0 +1,11 @@
# Example with all variables modifiable
```yaml
---
var1: 0 # The first variable
var2: 0 # The second variable
var3: 0 # The third variable
var4: 10 # This forth variable
var5: 10 # The fifth variable
var6: 10 # The sixth variable
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
var1: 1.1.1.1 # An IP
var2: 192.168.0.128/25 # An IP in CIDR format
var3: 1.1.1.1/24 # An IP in CIDR format with obsolete CIDR type
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
var1: 1.1.1.0 # An network
var2: 1.1.1.0/24 # An network in CIDR format
var3: 1.1.1.0/24 # An network in CIDR format with obsolete CIDR type
```

View file

@ -0,0 +1,11 @@
# Example with all variables modifiable
```yaml
---
var1: 0 # The first variable
var2: 0 # The second variable
var3: 0 # The third variable
var4: 10 # This forth variable
var5: 10 # The fifth variable
var6: 10 # The sixth variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
variable1: '111' # A port variable
```
# Example with all variables modifiable
```yaml
---
variable1: '111' # A port variable
variable2: '8080' # A port variable with default value
variable3: '8080' # A port variable with integer default value
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var: '#b1b1b1' # A first variable
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
var1: '#b1b1b1' # A first variable
var2: '#b2b1b1' # A second variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
secret1: secrets # The first variable
```
# Example with all variables modifiable
```yaml
---
secret1: secrets # The first variable
secret2: value # The second variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
secret1: secrets # The first variable
```
# Example with all variables modifiable
```yaml
---
secret1: secrets # The first variable
secret2: value # The second variable
secret3: value # The third variable
```

View file

@ -0,0 +1,21 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # The first variable
var2: example # The second variable
var3: example # The third variable
```
# Example with all variables modifiable
```yaml
---
var1: example # The first variable
var2: example # The second variable
var3: example # The third variable
var4: value # The forth variable
var5: value # The fifth variable
var6: value # The sixth variable
var7: '8080' # The seventh variable
var8: 'true' # The height variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var: quote' # A choice
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # The first variable
var2: example # The second variable
```
# Example with all variables modifiable
```yaml
---
var1: example # The first variable
var2: example # The second variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # The first variable
var2: example # The second variable
```
# Example with all variables modifiable
```yaml
---
var1: example # The first variable
var2: example # The second variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # The first <variable>
var2: example # The second <variable>
```
# Example with all variables modifiable
```yaml
---
var1: example # The first <variable>
var2: example # The second <variable>
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: quote" # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: quote'" # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: quote\"\' # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: quote' # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: example # A variable
```

View file

@ -0,0 +1,23 @@
# Example with mandatory variables not filled in
```yaml
---
var1: test # The first variable
var3: test1 # The third variable
var6: # The sixth variable
- test1
- test2
```
# Example with all variables modifiable
```yaml
---
var1: test # The first variable
var2: test # The second variable
var3: test1 # The third variable
var4: # The forth variable
var5: false # The fifth variable
var6: # The sixth variable
- test1
- test2
```

View file

@ -0,0 +1,16 @@
# Example with mandatory variables not filled in
```yaml
---
variable1: # A first variable
- a_choice
```
# Example with all variables modifiable
```yaml
---
variable1: # A first variable
- a_choice
variable2: # A second variable
- a_choice
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
source_variable_1: val1 # The first source variable
source_variable_2: val2 # The second source variable
my_variable: val1 # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: string_1_True_None # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var: example # A variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # A first variable
```
# Example with all variables modifiable
```yaml
---
var1: example # A first variable
var2: example # A second variable
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
my_variable: val1
my_calculated_variable:
- val1
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
my_variable: val1
my_calculated_variable:
- val1
```

View file

@ -0,0 +1,9 @@
# Example with all variables modifiable
```yaml
---
my_variable: val1
my_calculated_variable:
- val1
- value
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
my_calculated_variable:
- example
```
# Example with all variables modifiable
```yaml
---
my_calculated_variable:
- example
```

View file

@ -0,0 +1,11 @@
# Example with all variables modifiable
```yaml
---
my_variable:
- val1
- val2
my_calculated_variable:
- val1
- val2
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
var1: no # A first variable
var2: no # A second variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # A first variable
```
# Example with all variables modifiable
```yaml
---
var1: example # A first variable
var2: example # A second variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # A first variable
```
# Example with all variables modifiable
```yaml
---
var1: example # A first variable
var2: example # A second variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var: 9 # A variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var: 9 # A variable
```

View file

@ -0,0 +1,21 @@
# Example with all variables modifiable
```yaml
---
var1: # The first variable
- true
var2: # The second variable
- true
var3: # The third variable
- true
var4: # The forth variable
- false
var5: # The fifth variable
- false
var6: # The sixth variable
- false
var7: # The seventh variable
- true
var8: # The eighth variable
- true
```

View file

@ -0,0 +1,16 @@
# Example with mandatory variables not filled in
```yaml
---
custom1: # A first custom variable
- xxx
```
# Example with all variables modifiable
```yaml
---
custom1: # A first custom variable
- xxx
custom2: # A second custom variable
- value
```

View file

@ -0,0 +1,21 @@
# Example with all variables modifiable
```yaml
---
var1: # The first variable
- 0.0
var2: # The second variable
- 0.0
var3: # The third variable
- 0.0
var4: # The forth variable
- 10.1
var5: # The fifth variable
- 10.1
var6: # The sixth variable
- 10.1
var7: # The seventh variable
- 0.0
var8: # The eighth variable
- 0.0
```

View file

@ -0,0 +1,21 @@
# Example with all variables modifiable
```yaml
---
var1: # The first variable
- 0
var2: # The second variable
- 0
var3: # The third variable
- 0
var4: # The forth variable
- 10
var5: # The fifth variable
- 10
var6: # The sixth variable
- 10
var7: # The seventh variable
- 0
var8: # The eighth variable
- 0
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var: # The first variable
- 42
```
# Example with all variables modifiable
```yaml
---
var: # The first variable
- 42
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
var1: # The second variable
- value
-
```

View file

@ -0,0 +1,32 @@
# Example with mandatory variables not filled in
```yaml
---
var1: # The first variable
- example
var2: # The second variable
- example
var3: # The third variable
- example
```
# Example with all variables modifiable
```yaml
---
var1: # The first variable
- example
var2: # The second variable
- example
var3: # The third variable
- example
var4: # The forth variable
- value
var5: # The fifth variable
- value
var6: # The sixth variable
- value
var7: # The seventh variable
- value
var8: # The eighth variable
- value
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
variable: # A variable
- quote"
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
variable: # A variable
- quote'"
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
variable: # A variable
- quote'
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
variable: # A variable
- example
```

View file

@ -0,0 +1,16 @@
# Example with mandatory variables not filled in
```yaml
---
variable2: a_choice # A second variable
```
# Example with all variables modifiable
```yaml
---
variable1: # A first variable
- a
- b
- c
variable2: a_choice # A second variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: c # A variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var1: example # The first variable
var2: example # The second variable
```
# Example with all variables modifiable
```yaml
---
var1: example # The first variable
var2: example # The second variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
int: 10 # A limited number
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
int: 10 # A limited integer
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
variable: no # An auto save variable
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
var1: no # A first variable
var2: no # A second variable
```

View file

@ -0,0 +1,7 @@
# Example with all variables modifiable
```yaml
---
var1: no # A first variable
var2: yes # A second variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var2: example # A second variable
```
# Example with all variables modifiable
```yaml
---
var1: value # A first variable
var2: example # A second variable
var3: value # A third variable
```

View file

@ -0,0 +1,14 @@
# Example with mandatory variables not filled in
```yaml
---
var2: example # A second variable
```
# Example with all variables modifiable
```yaml
---
var1: value # A first variable
var2: example # A second variable
var3: example # A third variable
```

View file

@ -0,0 +1,6 @@
# Example with all variables modifiable
```yaml
---
var3: value # A third variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var2: example # A second variable
```
# Example with all variables modifiable
```yaml
---
var2: example # A second variable
var3: value # A third variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var3: example # A third variable
```
# Example with all variables modifiable
```yaml
---
var1: value # A first variable
var3: example # A third variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
var3: example # A third variable
```
# Example with all variables modifiable
```yaml
---
var1: value # A first variable
var3: example # A third variable
```

View file

@ -0,0 +1,15 @@
# Example with mandatory variables not filled in
```yaml
---
variable1: example # A first variable
variable2: example # A seconde variable
```
# Example with all variables modifiable
```yaml
---
condition: no # A conditional variable
variable1: example # A first variable
variable2: example # A seconde variable
```

View file

@ -0,0 +1,8 @@
# Example with all variables modifiable
```yaml
---
condition: no # A condition
var1: example # A first variable
var2: example # A second variable
```

View file

@ -0,0 +1,9 @@
# Example with all variables modifiable
```yaml
---
condition: false # A condition
var1: example # A first variable
var3: example # A second variable
var4: example # A forth variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
variable: example # A variable
```
# Example with all variables modifiable
```yaml
---
condition: false # A condition
variable: example # A variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
variable: example # A variable
```
# Example with all variables modifiable
```yaml
---
condition: true # A condition
variable: example # A variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
variable: example # A variable
```
# Example with all variables modifiable
```yaml
---
condition: true # A condition
variable: example # A variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
variable: example # A variable
```
# Example with all variables modifiable
```yaml
---
condition: yes # A condition
variable: example # A variable
```

View file

@ -0,0 +1,13 @@
# Example with mandatory variables not filled in
```yaml
---
variable: example # A variable
```
# Example with all variables modifiable
```yaml
---
condition: yes # A condition
variable: example # A variable
```

View file

@ -0,0 +1,12 @@
# Example with mandatory variables not filled in
```yaml
---
variable: example # A variable
```
# Example with all variables modifiable
```yaml
---
variable: example # A variable
```

Some files were not shown because too many files have changed in this diff Show more