diff options
author | rebortg <github@ghlr.de> | 2022-08-12 10:54:10 +0200 |
---|---|---|
committer | rebortg <git@ghlr.de> | 2022-08-16 15:38:16 +0200 |
commit | e9236755bb544c43c9949926ad4a3b85223612f5 (patch) | |
tree | 0438f6d468d625bb4c4bf9c52bb8298d19e13ca8 /docs/_ext/vyos.py | |
parent | 656cc5732a99525f381974a9a912f2538f0acd88 (diff) | |
download | vyos-documentation-e9236755bb544c43c9949926ad4a3b85223612f5.tar.gz vyos-documentation-e9236755bb544c43c9949926ad4a3b85223612f5.zip |
add :defaultvalue: option
(cherry picked from commit b09f2222ed6181ba377a41de37a3997559a234c8)
(cherry picked from commit 1205c1e7806d4e84e03aafc94831248cbfa9b1c8)
Diffstat (limited to 'docs/_ext/vyos.py')
-rw-r--r-- | docs/_ext/vyos.py | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/docs/_ext/vyos.py b/docs/_ext/vyos.py index cd8e561d..61b7519d 100644 --- a/docs/_ext/vyos.py +++ b/docs/_ext/vyos.py @@ -2,6 +2,7 @@ import re import json import os from datetime import datetime +from unittest import defaultTestLoader from docutils import io, nodes, utils, statemachine from docutils.parsers.rst.roles import set_classes from docutils.parsers.rst import Directive, directives, states @@ -398,6 +399,21 @@ class OpcmdlistDirective(Directive): return [oplist] +def get_default_value(title_text, config, cfgmode): + title_text = strip_cmd(title_text) + for cmd in config.vyos_working_commands[cfgmode]: + cmd_joined = ' '.join(cmd['name']) + cmd_striped = strip_cmd(cmd_joined) + if "table-size" in cmd['name']: + pass + #print(cmd) + #print(cmd_striped) + #print(title_text) + #print() + if cmd_striped == title_text: + if cmd['defaultvalue']: + return cmd['defaultvalue'] + return None class CmdDirective(SphinxDirective): @@ -410,19 +426,31 @@ class CmdDirective(SphinxDirective): content_list = [] title_text = '' content_text = '' + defaultvalue = None has_body = False cfgmode = self.custom_class + "cmd" + try: + if '' in self.content: + index = self.content.index('') + title_list = self.content[0:index] + content_list = self.content[index + 1:] + + title_text = ' '.join(title_list) + content_text = content_text + '\n'.join(content_list) + has_body = True + else: + title_list = self.content + title_text = ' '.join(title_list) + except Exception as e: + print("error", e) - if '' in self.content: - index = self.content.index('') - title_list = self.content[0:index] - content_list = self.content[index + 1:] - title_text = ' '.join(title_list) - content_text = '\n'.join(content_list) - has_body = True - else: - title_text = ' '.join(self.content) + # render defaultvalue + if os.getenv('VYOS_DEFAULT') or ':defaultvalue:' in title_text: + value = get_default_value(title_list, self.config, cfgmode) + title_text = title_text.replace(":defaultvalue:", '') + if value: + defaultvalue = f"default: {value}\n" anchor_id = nodes.make_id(self.custom_class + "cmd-" + title_text) target = nodes.target(ids=[anchor_id]) @@ -444,6 +472,11 @@ class CmdDirective(SphinxDirective): heading_element['classes'] += [self.custom_class + 'cmd-heading'] panel_element.append(heading_element) + if defaultvalue: + defaultvalue_element = nodes.paragraph(text=defaultvalue) + defaultvalue_element['classes'] = ["defaultvalue"] + panel_element.append(defaultvalue_element) + append_list = { 'docname': self.env.docname, @@ -526,9 +559,11 @@ def strip_cmd(cmd, debug=False): if debug: print(cmd) cmd = re.sub('\s+','',cmd) + cmd = cmd.replace(':defaultvalue:','') if debug: print(cmd) print("") + return cmd def build_row(app, fromdocname, rowdata): |