简体   繁体   English

如何在Mercurial扩展中的现有命令上添加命令选项?

[英]How do I add a command option to an existing command in a Mercurial extension?

I'm working on an extension which includes a pre-commit hook. 我正在开发一个包含预提交挂钩的扩展。 I'd like to be able to receive a new option within my hook. 我希望能够收到一个新的选择。 However, if I add it using the cmdtable example from the documentation , substituting a reference to the existing commit command, it just overwrites the built-in options. 但是,如果我使用文档中cmdtable示例添加它,替换对现有commit命令的引用,则它只会覆盖内置选项。 What is the right way to do this? 什么是正确的方法?

This is possible by using extensions.wrapcommand : 这可以通过使用extensions.wrapcommand

def commit(originalcommit, ui, repo, **opts):
    return originalcommit(ui, repo, **opts)

def uisetup(ui):    
    entry = extensions.wrapcommand(commands.table, "commit", commit)
    entry[1].append(('', 'newcommitoption', None, ('Description for the new commit option')))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM