git命令接收的是
具有以下示例代码:
#!/usr/bin/env python3
import argparse
def main():
parser = argparse.ArgumentParser(description="Some Description")
parser.add_argument('some-arg')
args = parser.parse_args()
print(args)
if __name__ == '__main__':
main()
我将此代码添加到名为git-mycommand
的文件中,使其可执行,并将其复制到/usr/bin
。
现在尝试使用--help
运行命令,会给我意外的输出:
user@user:~$ git mycommand --help
No manual entry for git-mycommand
See 'man 7 undocumented' for help when manual pages are not available.
如果我在没有--help
的情况下正常运行命令,它会正常工作,比如:
oerp@oerp:~$ git mycommand some_val
Namespace(**{'some-arg': 'some_val'})
或者,如果我不将其用作git
子命令并直接运行它,比如:
oerp@oerp:~$ git-mycommand --help
usage: git-mycommand [-h] some-arg
Some Description
positional arguments:
some-arg
optional arguments:
-h, --help show this help message and exit
有人知道为什么自定义git
子命令不能与--help
参数一起正常工作吗?或者可能还有其他事情,我需要做,这样它就会显示预期的输出?
--help
选项,而不是您的子命令。
注意,
git --help ...
与git help ...
相同,因为前者在内部转换为后者。
https://git-scm.com/docs/git-help
git help
调用git help,打开给定命令的手册页。