diff options
author | Christian Breunig <christian@breunig.cc> | 2023-10-08 10:27:27 +0200 |
---|---|---|
committer | Christian Breunig <christian@breunig.cc> | 2023-10-08 10:27:27 +0200 |
commit | b6917f386e5f6af570973d42e63baeb4a98d6261 (patch) | |
tree | 6910c10e7a48fb97625edee2e8fa04940d56b28b /scripts/build-command-templates | |
parent | da4006c2a784ff06cf3af3aad6adee7fef8a5330 (diff) | |
download | vyos-1x-b6917f386e5f6af570973d42e63baeb4a98d6261.tar.gz vyos-1x-b6917f386e5f6af570973d42e63baeb4a98d6261.zip |
scripts: T4269: node.def generator should automatically add default values
Since introducing the XML <defaultValue> node it was common, but redundant,
practice to also add a help string indicating which value would be used as
default if the node is unset.
This makes no sense b/c it's duplicated code/value/characters and prone to
error. The node.def scripts should be extended to automatically render the
appropriate default value into the CLI help string.
For e.g. SSH the current PoC renders:
$ cat templates-cfg/service/ssh/port/node.def
multi:
type: txt
help: Port for SSH service (default: 22)
val_help: u32:1-65535; Numeric IP port
...
Not all subsystems are already migrated to get_config_dict() and make use of
the defaults() call - those subsystems need to be migrated, first before the new
default is added to the CLI help.
(cherry picked from commit a68c9238111c6caee78bb28f8054b8f0cfa0e374)
Diffstat (limited to 'scripts/build-command-templates')
-rwxr-xr-x | scripts/build-command-templates | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/scripts/build-command-templates b/scripts/build-command-templates index a0d1015b4..26ffd0745 100755 --- a/scripts/build-command-templates +++ b/scripts/build-command-templates @@ -117,7 +117,7 @@ def collect_validators(ve): return regex_args + " " + validator_args -def get_properties(p): +def get_properties(p, default=None): props = {} if p is None: @@ -125,7 +125,12 @@ def get_properties(p): # Get the help string try: - props["help"] = p.find("help").text + help = p.find("help").text + if default != None: + # DNS forwarding for instance has multiple defaults - specified as whitespace separated list + tmp = ', '.join(default.text.split()) + help += f' (default: {tmp})' + props["help"] = help except: pass @@ -134,7 +139,11 @@ def get_properties(p): vhe = p.findall("valueHelp") vh = [] for v in vhe: - vh.append( (v.find("format").text, v.find("description").text) ) + format = v.find("format").text + description = v.find("description").text + if default != None and default.text == format: + description += f' (default)' + vh.append( (format, description) ) props["val_help"] = vh except: props["val_help"] = [] @@ -271,7 +280,7 @@ def process_node(n, tmpl_dir): print("Name of the node: {0}. Created directory: {1}\n".format(name, "/".join(my_tmpl_dir)), end="") os.makedirs(make_path(my_tmpl_dir), exist_ok=True) - props = get_properties(props_elem) + props = get_properties(props_elem, n.find("defaultValue")) if owner: props["owner"] = owner # Type should not be set for non-tag, non-leaf nodes |