diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-01-07 23:01:10 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-01-30 19:11:03 +0100 |
commit | b4bd124be496170937d19742d83c2bad7471fe81 (patch) | |
tree | 0cd998483de30c688cf5130c90fd4ee94f47833c /generate_auto_job | |
parent | 5303130cf920ad9242bd1bb5ad998a791eb7e205 (diff) | |
download | qpdf-b4bd124be496170937d19742d83c2bad7471fe81.tar.zst |
QPDFArgParser: support adding/printing help information
Diffstat (limited to 'generate_auto_job')
-rwxr-xr-x | generate_auto_job | 86 |
1 files changed, 85 insertions, 1 deletions
diff --git a/generate_auto_job b/generate_auto_job index 2dc51105..556b374c 100755 --- a/generate_auto_job +++ b/generate_auto_job @@ -19,7 +19,7 @@ def warn(*args, **kwargs): class Main: - SOURCES = [whoami, 'job.yml'] + SOURCES = [whoami, 'job.yml', 'manual/cli.rst'] DESTS = { 'decl': 'libqpdf/qpdf/auto_job_decl.hh', 'init': 'libqpdf/qpdf/auto_job_init.hh', @@ -87,6 +87,88 @@ class Main: for k, v in hashes.items(): print(f'{k} {v}', file=f) + def generate_doc(self, df, f): + st_top = 0 + st_topic = 1 + st_option = 2 + st_option_help = 3 + state = st_top + + indent = None + topic = None + option = None + short_text = None + long_text = None + + print('this->ap.addHelpFooter("For detailed help, visit' + ' the qpdf manual: https://qpdf.readthedocs.io\\n");', file=f) + + def set_indent(x): + nonlocal indent + indent = ' ' * len(x) + + def append_long_text(line): + nonlocal indent, long_text + if line == '\n': + long_text += '\n' + elif line.startswith(indent): + long_text += line[len(indent):] + else: + long_text = long_text.strip() + if long_text != '': + long_text += '\n' + return True + return False + + lineno = 0 + for line in df.readlines(): + lineno += 1 + if state == st_top: + m = re.match(r'^(\s*\.\. )help-topic (\S+): (.*)$', line) + if m: + set_indent(m.group(1)) + topic = m.group(2) + short_text = m.group(3) + long_text = '' + state = st_topic + continue + m = re.match(r'^(\s*\.\. )qpdf:option:: (([^=\s]+)(=(\S+))?)$', + line) + if m: + if topic is None: + raise Exception('option seen before topic') + set_indent(m.group(1)) + option = m.group(3) + synopsis = m.group(2) + if synopsis.endswith('`'): + raise Exception( + f'stray ` at end of option line (line {lineno})') + if synopsis != option: + long_text = synopsis + '\n' + else: + long_text = '' + state = st_option + continue + elif state == st_topic: + if append_long_text(line): + print(f'this->ap.addHelpTopic("{topic}", "{short_text}",' + f' R"({long_text})");', file=f) + state = st_top + elif state == st_option: + if line == '\n' or line.startswith(indent): + m = re.match(r'^(\s*\.\. )help: (.*)$', line) + if m: + set_indent(m.group(1)) + short_text = m.group(2) + state = st_option_help + else: + state = st_top + elif state == st_option_help: + if append_long_text(line): + print(f'this->ap.addOptionHelp("{option}", "{topic}",' + f' "{short_text}", R"({long_text})");', file=f) + state = st_top + def generate(self): warn(f'{whoami}: regenerating auto job files') @@ -230,6 +312,8 @@ class Main: for j in ft['options']: print('this->ap.copyFromOtherTable' f'("{j}", "{other_table}");', file=f) + with open('manual/cli.rst', 'r') as df: + self.generate_doc(df, f) if __name__ == '__main__': |