This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateAdoc.py
64 lines (48 loc) · 2.21 KB
/
updateAdoc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from distutils.file_util import write_file
import os
import re
import sys
from pathlib import Path
logseqDir = os.getcwd()
dirName='/skupper-generate/podman/'
print(logseqDir)
for path in Path(logseqDir + dirName).iterdir():
mdFile=str(path)
if mdFile.endswith('.adoc'):
file = open(mdFile, "r")
replacement = ""
# using the for loop
for line in file:
line = line.strip()
changes=line
changes = changes.replace("==","=")
print(changes)
changes = changes.replace('== Synopsis','.Synopsis')
changes = changes.replace('----','```')
changes = changes.replace('== Options', '.Options')
# find end material
#
changes = changes.replace('=== Auto ','// Auto ')
changes = changes.replace('=== Options ','// Options')
changes = changes.replace('.* -h, --help .*','// ')
changes = changes.replace(' -c, --context string The kubeconfig context to use','// ')
changes = changes.replace('.*--kubeconfig.*','// ')
changes = changes.replace(' -n, --namespace string The Kubernetes namespace to use','// ')
# find options
if (result := re.match(r"skupper (.*)\[flags\]", line)) is not None:
changes= ' skupper ' + result[1] + ' --[option]\n\n'
if (result := re.match(r" --(.*)\b(.*)?[ ]{2,}(.*)", line)) is not None:
if (optionType := re.split(r"\s", result[1])) is not None:
if len(optionType)>1:
changes= optionType[0] + ':: \n' + result[3] + '\n ('+ optionType[1] +')\n'
else:
changes= optionType[0] + ':: \n' + result[3] + '\n (bool)\n'
changes = changes.replace('== SEE ALSO','.See also')
changes = changes.replace('[discrete\]','')
changes = changes.replace('^====','// ')
replacement = replacement + changes + "\n"
file.close()
# opening the file in write mode
fout = open(mdFile, "w")
fout.write(replacement)
fout.close()