def write_man_pages(name, cli, parent_ctx=None, version=None, target_dir=None):
"""
Generate man page files recursively
for the given click cli function.
:param str name: the cli name
:param cli: the cli instance
:param click.Context parent_ctx: the parent click context
:param str target_dir: the directory where the generated
man pages are stored.
"""
ctx = click.Context(cli, info_name=name, parent=parent_ctx)
man_page = generate_man_page(ctx, version)
path = '{0}.1'.format(ctx.command_path.replace(' ', '-'))
if target_dir:
path = os.path.join(target_dir, path)
with open(path, 'w+') as f:
f.write(man_page)
commands = getattr(cli, 'commands', {})
for name, command in commands.items():
write_man_pages(name, command, parent_ctx=ctx, version=version, target_dir=target_dir)
评论列表
文章目录