我試圖在python中創建一個複雜的mercurial commit hook。我也想被允許使用OptionParser傳遞參數。這裏是什麼,我至今要點:Mercurial Commit with Python主函數
.hg/hgrc配置:
[hooks]
commit = python:/mydir/pythonFile.py:main
# using python:/mydir/pythonFile.py doesn't work for some reason either
pythonFile.py:
def main(ui, repo, **kwargs):
from optparse import OptionParser
parser = OptionParser()
parser.add_option('--test-dir', action='store', type="string",
dest='test_dir', default='otherdir/',
help='help info')
(options, args) = parser.parse_args()
# do some stuff here
someFunc(options.test_dir)
if __name__ == '__main__':
import sys
main(sys.argv[0], sys.argv[1], sys.argv[2:])
當我運行hg commit -m 'message'
我得到一個錯誤:「用法:hg [options] hg:error:no such option:-m「。當我嘗試hg commit --test-dir '/somedir'
時,出現錯誤:「hg commit:option --test-dir not recognized」。
最後我試圖在hgrc配置指定commit = python:/mydir/pythonFile.py:main --test-dir '/somedir'
,我得到這個錯誤:「AttributeError的:‘模塊’對象有沒有屬性‘主--test-DIR‘/ somedir’’」
感謝您幫幫我。