我有一个与此 SO Q&A有点相似的问题,但是我想在click生成的输出末尾的 Epilog 中添加额外的空白行。
我有以下代码:
EPILOG='\n' + '-' * 20
class SpecialEpilog(click.Group):
def format_epilog(self, ctx, formatter):
if self.epilog:
formatter.write_paragraph()
for line in self.epilog.split('\n'):
formatter.write_text(line)
#------------------
@click.group(cls=SpecialEpilog, epilog=EPILOG, invoke_without_command=True)
def cli():
"""Wraps cloud.tenable.com Nessus API calls in useful ways
\b
The CLI provides access to these subcommands:
- agent
- os
- vuln
Each subcommand can perform useful API queries within their respective domain.
"""
pass
#------------------
# main
cli.add_command(os)
cli.add_command(agent)
cli.add_command(vuln)
这会产生以下使用输出:
Usage: nessus_query [OPTIONS] COMMAND [ARGS]...
Wraps cloud.tenable.com Nessus API calls in useful ways
The CLI provides access to these subcommands:
- agent
- os
- vuln
Each subcommand can perform useful API queries within their respective
domain.
Options:
--help Show this message and exit.
Commands:
agent API calls focusing on assets' details - Works...
os API calls focusing on operating systems -...
vuln API calls focusing on vulnerabilities - Works...
--------------------
$ myprompt>
我的问题:
我想不出一种不需要可打印字符的方法。\n
如果我删除上面的破折号序列,则不再显示换行符 ( )。换句话说,上面的用法是这样的:
...
Commands:
agent API calls focusing on assets' details - Works...
os API calls focusing on operating systems -...
vuln API calls focusing on vulnerabilities - Works...
$ myprompt>