Skip to content

Commit f0d09e3

Browse files
Dev: doc/toolchain: implement adocxt (#1374)
extracts sections needed to be generated from argparse help from tags in crm.8.adoc and generates Makefile for building those adocs
1 parent d490294 commit f0d09e3

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
doc/website-v1/gen
66
Makefile.in
77
autom4te.cache
8-
Makefile
8+
./Makefile
99
aclocal.m4
1010
autoconf
1111
autoheader

doc/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated-sources/

doc/Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.PHONY: all clean subdirs
2+
3+
all: subdirs generated-sources/crm.8.adoc
4+
5+
generated-sources:
6+
mkdir -p $@
7+
8+
generated-sources/Makefile: crm.8.adoc generated-sources
9+
adocxt gen-makefile < $< > $@
10+
11+
subdirs: generated-sources/Makefile
12+
$(MAKE) -C generated-sources all
13+
14+
generated-sources/crm.8.adoc: crm.8.adoc generated-sources
15+
adocxt gen-include < $< > $@
16+
17+
clean:
18+
$(RM) -r generated-sources

doc/toolchain/bin/adocxt

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
3+
4+
import re
5+
import shlex
6+
import sys
7+
import typing
8+
9+
10+
RE_FROM_CODE = re.compile(r'^\[\[([^,]+),[^,]*,From Code]]$')
11+
RE_TAG = re.compile('^cmdhelp_(.*)$')
12+
13+
TAG_EXCLUDES = {
14+
'cmdhelp_node_online',
15+
'cmdhelp_node_standby',
16+
'cmdhelp_root_report',
17+
}
18+
19+
20+
def main(stdin, stdout):
21+
tags = list()
22+
for line in stdin:
23+
found = RE_FROM_CODE.match(line)
24+
if found:
25+
tag = found.group(1)
26+
if tag in TAG_EXCLUDES:
27+
continue
28+
command = extract_command(tag)
29+
tags.append(tag)
30+
stdout.write(tag)
31+
stdout.write('.txt:\n\t')
32+
stdout.write(shlex.join(command))
33+
stdout.write(' > "$@"\n\n')
34+
end(tags, stdout)
35+
36+
37+
def extract_command(tag: str) -> typing.Sequence[str]:
38+
found = RE_TAG.match(tag)
39+
if not found:
40+
raise RuntimeError(f'Invalid tag {tag}')
41+
args = ['crm']
42+
args.extend(found.group(1).split('_', 1))
43+
args.append('--help-without-redirect')
44+
return args
45+
46+
47+
def end(tags: typing.Sequence[str], stdout):
48+
stdout.write(
49+
'%.adoc: %.txt\n\thelp2adoc "$<"\n\n'
50+
)
51+
stdout.write(
52+
'.PHONY: clean all\n\nclean:\n\t$RM *.txt *.adoc\n\nall: '
53+
)
54+
for tag in tags:
55+
stdout.write(tag)
56+
stdout.write('.adoc ')
57+
stdout.write('\n\n')
58+
59+
60+
61+
if __name__ == '__main__':
62+
main(sys.stdin, sys.stdout)

0 commit comments

Comments
 (0)