Skip to content

Commit

Permalink
Dev: doc/toolchain: implement adocxt (ClusterLabs#1374)
Browse files Browse the repository at this point in the history
extracts sections needed to be generated from argparse help from tags in
crm.8.adoc and generates Makefile for building those adocs
  • Loading branch information
nicholasyang2022 committed Apr 8, 2024
1 parent d06dad7 commit 313631f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
doc/website-v1/gen
Makefile.in
autom4te.cache
Makefile
./Makefile
aclocal.m4
autoconf
autoheader
Expand Down
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated-sources/
18 changes: 18 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: all clean subdirs

all: subdirs generated-sources/crm.8.adoc

generated-sources:
mkdir -p $@

generated-sources/Makefile: crm.8.adoc generated-sources
adocxt gen-makefile < $< > $@

subdirs: generated-sources/Makefile
$(MAKE) -C generated-sources all

generated-sources/crm.8.adoc: crm.8.adoc generated-sources
adocxt gen-include < $< > $@

clean:
$(RM) -r generated-sources
62 changes: 62 additions & 0 deletions doc/toolchain/bin/adocxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3


import re
import shlex
import sys
import typing


RE_FROM_CODE = re.compile(r'^\[\[([^,]+),[^,]*,From Code]]$')
RE_TAG = re.compile('^cmdhelp_(.*)$')

TAG_EXCLUDES = {
'cmdhelp_node_online',
'cmdhelp_node_standby',
'cmdhelp_root_report',
}


def main(stdin, stdout):
tags = list()
for line in stdin:
found = RE_FROM_CODE.match(line)
if found:
tag = found.group(1)
if tag in TAG_EXCLUDES:
continue
command = extract_command(tag)
tags.append(tag)
stdout.write(tag)
stdout.write('.txt:\n\t')
stdout.write(shlex.join(command))
stdout.write(' > "$@"\n\n')
end(tags, stdout)


def extract_command(tag: str) -> typing.Sequence[str]:
found = RE_TAG.match(tag)
if not found:
raise RuntimeError(f'Invalid tag {tag}')
args = ['crm']
args.extend(found.group(1).split('_', 1))
args.append('--help-without-redirect')
return args


def end(tags: typing.Sequence[str], stdout):
stdout.write(
'%.adoc: %.txt\n\thelp2adoc "$<"\n\n'
)
stdout.write(
'.PHONY: clean all\n\nclean:\n\t$RM *.txt *.adoc\n\nall: '
)
for tag in tags:
stdout.write(tag)
stdout.write('.adoc ')
stdout.write('\n\n')



if __name__ == '__main__':
main(sys.stdin, sys.stdout)

0 comments on commit 313631f

Please sign in to comment.