forked from ClusterLabs/crmsh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: doc/toolchain: implement adocxt (ClusterLabs#1374)
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
1 parent
d06dad7
commit 313631f
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
doc/website-v1/gen | ||
Makefile.in | ||
autom4te.cache | ||
Makefile | ||
./Makefile | ||
aclocal.m4 | ||
autoconf | ||
autoheader | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
generated-sources/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |