mirror of
https://github.com/vyos/vyos-documentation.git
synced 2025-10-26 08:41:46 +01:00
add :defaultvalue: option
(cherry picked from commit b09f2222ed6181ba377a41de37a3997559a234c8) (cherry picked from commit 1205c1e7806d4e84e03aafc94831248cbfa9b1c8)
This commit is contained in:
parent
656cc5732a
commit
e9236755bb
@ -27,3 +27,7 @@ livehtml:
|
|||||||
sphinx-autobuild --host $(AUTOHOST) --port $(AUTOPORT) $(AUTOOPTS) \
|
sphinx-autobuild --host $(AUTOHOST) --port $(AUTOPORT) $(AUTOOPTS) \
|
||||||
"$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
"$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
||||||
|
|
||||||
|
defaultvalue: export VYOS_DEFAULT=True
|
||||||
|
defaultvalue:
|
||||||
|
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
@ -175,12 +175,18 @@ def get_properties(p):
|
|||||||
|
|
||||||
def process_node(n, f):
|
def process_node(n, f):
|
||||||
|
|
||||||
|
|
||||||
props_elem = n.find("properties")
|
props_elem = n.find("properties")
|
||||||
children = n.find("children")
|
children = n.find("children")
|
||||||
command = n.find("command")
|
command = n.find("command")
|
||||||
children_nodes = []
|
children_nodes = []
|
||||||
owner = n.get("owner")
|
owner = n.get("owner")
|
||||||
node_type = n.tag
|
node_type = n.tag
|
||||||
|
defaultvalue = n.find("defaultValue")
|
||||||
|
|
||||||
|
if defaultvalue is not None:
|
||||||
|
defaultvalue = defaultvalue.text
|
||||||
|
|
||||||
|
|
||||||
name = n.get("name")
|
name = n.get("name")
|
||||||
props = get_properties(props_elem)
|
props = get_properties(props_elem)
|
||||||
@ -218,7 +224,9 @@ def process_node(n, f):
|
|||||||
'children': children_nodes,
|
'children': children_nodes,
|
||||||
'props': props,
|
'props': props,
|
||||||
'command': test_command,
|
'command': test_command,
|
||||||
'filename': f
|
'filename': f,
|
||||||
|
'defaultvalue': defaultvalue
|
||||||
|
|
||||||
}
|
}
|
||||||
return node
|
return node
|
||||||
|
|
||||||
@ -232,9 +240,11 @@ def create_commands(data, parent_list=[], level=0):
|
|||||||
'tag_help': [],
|
'tag_help': [],
|
||||||
'level': level,
|
'level': level,
|
||||||
'no_childs': False,
|
'no_childs': False,
|
||||||
'filename': None
|
'filename': None,
|
||||||
|
'defaultvalue': None,
|
||||||
}
|
}
|
||||||
command['filename'] = data['filename']
|
command['filename'] = data['filename']
|
||||||
|
command['defaultvalue'] = data['defaultvalue']
|
||||||
command['name'].extend(parent_list)
|
command['name'].extend(parent_list)
|
||||||
command['name'].append(data['name'])
|
command['name'].append(data['name'])
|
||||||
|
|
||||||
@ -348,6 +358,7 @@ def get_working_commands():
|
|||||||
'children': [],
|
'children': [],
|
||||||
'command': node_data[kind][entry]['command'],
|
'command': node_data[kind][entry]['command'],
|
||||||
'filename': node_data[kind][entry]['filename'],
|
'filename': node_data[kind][entry]['filename'],
|
||||||
|
'defaultvalue': node_data[kind][entry]['defaultvalue']
|
||||||
}
|
}
|
||||||
config_tree_new[kind][node_0]['children'].extend(node_data[kind][entry]['children'])
|
config_tree_new[kind][node_0]['children'].extend(node_data[kind][entry]['children'])
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import re
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from unittest import defaultTestLoader
|
||||||
from docutils import io, nodes, utils, statemachine
|
from docutils import io, nodes, utils, statemachine
|
||||||
from docutils.parsers.rst.roles import set_classes
|
from docutils.parsers.rst.roles import set_classes
|
||||||
from docutils.parsers.rst import Directive, directives, states
|
from docutils.parsers.rst import Directive, directives, states
|
||||||
@ -398,6 +399,21 @@ class OpcmdlistDirective(Directive):
|
|||||||
return [oplist]
|
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):
|
class CmdDirective(SphinxDirective):
|
||||||
|
|
||||||
@ -410,19 +426,31 @@ class CmdDirective(SphinxDirective):
|
|||||||
content_list = []
|
content_list = []
|
||||||
title_text = ''
|
title_text = ''
|
||||||
content_text = ''
|
content_text = ''
|
||||||
|
defaultvalue = None
|
||||||
has_body = False
|
has_body = False
|
||||||
|
|
||||||
cfgmode = self.custom_class + "cmd"
|
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:]
|
||||||
|
|
||||||
if '' in self.content:
|
title_text = ' '.join(title_list)
|
||||||
index = self.content.index('')
|
content_text = content_text + '\n'.join(content_list)
|
||||||
title_list = self.content[0:index]
|
has_body = True
|
||||||
content_list = self.content[index + 1:]
|
else:
|
||||||
title_text = ' '.join(title_list)
|
title_list = self.content
|
||||||
content_text = '\n'.join(content_list)
|
title_text = ' '.join(title_list)
|
||||||
has_body = True
|
except Exception as e:
|
||||||
else:
|
print("error", e)
|
||||||
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)
|
anchor_id = nodes.make_id(self.custom_class + "cmd-" + title_text)
|
||||||
target = nodes.target(ids=[anchor_id])
|
target = nodes.target(ids=[anchor_id])
|
||||||
@ -444,6 +472,11 @@ class CmdDirective(SphinxDirective):
|
|||||||
heading_element['classes'] += [self.custom_class + 'cmd-heading']
|
heading_element['classes'] += [self.custom_class + 'cmd-heading']
|
||||||
|
|
||||||
panel_element.append(heading_element)
|
panel_element.append(heading_element)
|
||||||
|
if defaultvalue:
|
||||||
|
defaultvalue_element = nodes.paragraph(text=defaultvalue)
|
||||||
|
defaultvalue_element['classes'] = ["defaultvalue"]
|
||||||
|
panel_element.append(defaultvalue_element)
|
||||||
|
|
||||||
|
|
||||||
append_list = {
|
append_list = {
|
||||||
'docname': self.env.docname,
|
'docname': self.env.docname,
|
||||||
@ -526,9 +559,11 @@ def strip_cmd(cmd, debug=False):
|
|||||||
if debug:
|
if debug:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
cmd = re.sub('\s+','',cmd)
|
cmd = re.sub('\s+','',cmd)
|
||||||
|
cmd = cmd.replace(':defaultvalue:','')
|
||||||
if debug:
|
if debug:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def build_row(app, fromdocname, rowdata):
|
def build_row(app, fromdocname, rowdata):
|
||||||
|
|||||||
6
docs/_static/css/custom.css
vendored
6
docs/_static/css/custom.css
vendored
@ -87,6 +87,12 @@ span.opcmd:before {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.defaultvalue{
|
||||||
|
font-size: 90%;
|
||||||
|
color: gray;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
a.cmdlink {
|
a.cmdlink {
|
||||||
font-size: 80%;
|
font-size: 80%;
|
||||||
|
|||||||
@ -295,6 +295,21 @@ For an inline configuration level command, use ``:cfgcmd:``
|
|||||||
|
|
||||||
:cfgcmd:`set interface ethernet eth0`
|
:cfgcmd:`set interface ethernet eth0`
|
||||||
|
|
||||||
|
|
||||||
|
To extract a defaultvalue from the XML definitions add a ``:defaultvalue:``
|
||||||
|
to ``.. cfgcmd::`` directive.
|
||||||
|
To have this feature locally, the vyos-1x submodule must be initialized before.
|
||||||
|
Please be aware to not update the submodule in your PR.
|
||||||
|
|
||||||
|
.. code-block:: none
|
||||||
|
|
||||||
|
.. cfgcmd:: set system conntrack table-size <1-50000000>
|
||||||
|
:defaultvalue:
|
||||||
|
|
||||||
|
The connection tracking table contains one entry for each connection being
|
||||||
|
tracked by the system.
|
||||||
|
|
||||||
|
|
||||||
opcmd
|
opcmd
|
||||||
"""""
|
"""""
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user