diff options
author | rebortg <github@ghlr.de> | 2022-03-29 20:00:53 +0200 |
---|---|---|
committer | rebortg <github@ghlr.de> | 2022-03-29 20:02:48 +0200 |
commit | 235ca6cdbb39c0e31dec750f97a033638fb072ba (patch) | |
tree | c33029b8dd2b1b80f58a654ca4043c8028616cb2 /docs | |
parent | fbdf9fef0f5119c4f4ac46ca2827cc427ed53668 (diff) | |
download | vyos-documentation-235ca6cdbb39c0e31dec750f97a033638fb072ba.tar.gz vyos-documentation-235ca6cdbb39c0e31dec750f97a033638fb072ba.zip |
coverage: improve command comparing
(cherry picked from commit 76d521bd070f5ca2aca09fc760cea771cbfb08fd)
Diffstat (limited to 'docs')
-rw-r--r-- | docs/_ext/vyos.py | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/docs/_ext/vyos.py b/docs/_ext/vyos.py index 6832167f..fbdfefab 100644 --- a/docs/_ext/vyos.py +++ b/docs/_ext/vyos.py @@ -437,20 +437,45 @@ class CfgCmdDirective(CmdDirective): def strip_cmd(cmd, debug=False): + + # find all [...] and also nested [...] + # regex and str.find() had problems with nested [...] + appearance = 0 + cmd_new = "" + for c in cmd: + if c == "[": + appearance = appearance + 1 + if appearance == 0: + cmd_new = f"{cmd_new}{c}" + if c == "]": + appearance = appearance - 1 + + # only if all [..] will be delete if appearance > 0 there is a syntax errror + if appearance == 0: + cmd = cmd_new + + # same for <...> + appearance = 0 + cmd_new = "" + for c in cmd: + if c == "<": + appearance = appearance + 1 + if appearance == 0: + cmd_new = f"{cmd_new}{c}" + if c == ">": + appearance = appearance - 1 + + # only if all <..> will be delete if appearance > 0 there is a syntax errror + if appearance == 0: + cmd = cmd_new + if debug: print("") print(cmd) - cmd = re.sub('set','',cmd) + cmd = re.sub('^set','',cmd) if debug: print(cmd) - #while " | " in cmd: - cmd = re.sub('\s+\|\s+','',cmd) - if debug: - print(cmd) - cmd = re.sub('<\S*>','',cmd) - if debug: - print(cmd) - cmd = re.sub('\[\S\]','',cmd) + cmd = cmd.replace('|','') if debug: print(cmd) cmd = re.sub('\s+','',cmd) @@ -502,9 +527,6 @@ def process_coverage(app, fromdocname, doccmd, xmlcmd, cli_type): coverage_list[strip_cmd(cmd['cmd'])] = dict(coverage_item) - - #print(coverage_list.keys()) - for cmd in xmlcmd: strip = strip_cmd(cmd['cmd']) @@ -668,5 +690,3 @@ def handle_document_meta_data(app, document): else: pass #logger.warning(f'lastproofread meta data missing in {app.env.doc2path(docname)}') - - |