From: Kefu Chai Date: Fri, 12 Feb 2021 08:03:11 +0000 (+0800) Subject: doc: group commands by prefix X-Git-Tag: v17.1.0~2986^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=642158fd381fa0b02a75a3e47665b43fc3ba6f51;p=ceph.git doc: group commands by prefix as there are lots commands, the toc in sidebar is clutterred with them, so would be better to group them. Signed-off-by: Kefu Chai --- diff --git a/doc/_ext/ceph_commands.py b/doc/_ext/ceph_commands.py index e0f1090be35b..d52949f17ff1 100644 --- a/doc/_ext/ceph_commands.py +++ b/doc/_ext/ceph_commands.py @@ -179,12 +179,19 @@ class Sig: TEMPLATE = ''' -.. This file is automatically generated. do not modify +{% set punct_char = '-' %} +{# add a header if we have multiple commands in this section #} +{% if commands | length > 1 %} +{{ section }} +{{ section | length * '-' }} +{# and demote the subsection #} +{% set punct_char = '^' %} +{% endif %} {% for command in commands %} {{ command.prefix }} -{{ command.prefix | length * '^' }} +{{ command.prefix | length * punct_char }} {{ command.help | wordwrap(70)}} @@ -215,6 +222,36 @@ Required Permissions: ''' +def group_by_prefix(commands): + last_prefix = None + grouped = [] + for cmd in commands: + prefix = cmd.prefix.split(' ', 1)[0] + if prefix == last_prefix: + grouped.append(cmd) + elif last_prefix is None: + last_prefix = prefix + grouped = [cmd] + else: + yield last_prefix, grouped + last_prefix = prefix + grouped = [cmd] + assert grouped + yield last_prefix, grouped + + +def render_commands(commands): + rendered = io.StringIO() + for section, grouped in group_by_prefix(commands): + logger.debug('rendering commands: %s: %d', section, len(grouped)) + for cmd in grouped: + logger.info('%s ==> %s', section, cmd.prefix) + rendered.write(Template(TEMPLATE).render( + section=section, + commands=grouped)) + return rendered.getvalue().split('\n') + + class CephMgrCommands(Directive): """ extracts commands from specified mgr modules @@ -309,8 +346,7 @@ class CephMgrCommands(Directive): return command def _render_cmds(self, commands): - rendered = Template(TEMPLATE).render(commands=list(commands)) - lines = rendered.split("\n") + lines = render_commands(commands) assert lines lineno = self.lineno - self.state_machine.input_offset - 1 source = self.state_machine.input_lines.source(lineno) @@ -413,8 +449,7 @@ class CephMonCommands(Directive): return command def _render_cmds(self, commands): - rendered = Template(TEMPLATE).render(commands=list(commands)) - lines = rendered.split("\n") + lines = render_commands(commands) assert lines lineno = self.lineno - self.state_machine.input_offset - 1 source = self.state_machine.input_lines.source(lineno)