我试图使用pdoc来记录我的python脚本,但是由于我的程序需要使用命令行args,所以我遇到了一个问题。
我的程序名为:myprogram.py -p arg1 -s arg2
我试着按以下方式运行pdoc:pdoc --html myprogram
但我说pdoc: error: the following arguments are required: -p时出错了
但是,如果我尝试像这样运行pdoc:pdoc --html myprogram.py -p arg1 -s arg2,则会得到以下错误:
pdoc: error: unrecognized arguments: -p arg1 -s arg2
有办法在需要命令行args的模块上运行pdoc吗?
发布于 2020-04-15 17:57:27
从pdoc the documented modules开始,您需要在main guard下嵌套CLI程序执行。
def main():
from argparse import ArgumentParser
parser = ArgumentParser(...)
args = parser.parse_args()
...
if __name__ == '__main__':
# Run main entry point only if the script was run as a program
# and not if it was merely imported
main()https://stackoverflow.com/questions/58610226
复制相似问题