doc/_ext: define a helper for current_module()

less repeating this way, this change also addresses the missing option
issue if the option to be rendered is the first option in a document,
and there is no "mgr_module" directive before it.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2021-05-10 11:56:54 +08:00
parent f948b5acf7
commit 44e611ce30

View File

@ -339,8 +339,12 @@ class CephOption(ObjectDescription):
CephOption.mgr_opts[module] = dict((opt['name'], opt) for opt in opts)
return CephOption.mgr_opts[module]
def _current_module(self) -> str:
return self.options.get('module',
self.env.ref_context.get('ceph:module'))
def _render_option(self, name) -> str:
cur_module = self.env.ref_context.get('ceph:module')
cur_module = self._current_module()
if cur_module:
opt = self._load_module(cur_module).get(name)
else:
@ -369,8 +373,7 @@ class CephOption(ObjectDescription):
signode += addnodes.desc_name(sig, sig)
# normalize whitespace like XRefRole does
name = ws_re.sub(' ', sig)
cur_module = self.options.get('module',
self.env.ref_context.get('ceph:module'))
cur_module = self._current_module()
if cur_module:
return '/'.join(['mgr', cur_module, name])
else: