Mercurial > hg > evolve
changeset 974:4f21a3279a60
evolve: add function to deprecate an alias
When cleaning up the UI for evolve we will deprecate old aliases,
but still want them to work for a while. This is a helper function
that will be called during the extension setup and has the ability
map an old alias to a new or canonical one.
author | Olle Lundberg <geek@nerd.sh> |
---|---|
date | Fri, 04 Apr 2014 00:30:56 +0200 |
parents | 7de15cfd79f7 |
children | 17ac69db9329 |
files | hgext/evolve.py |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/evolve.py +++ b/hgext/evolve.py @@ -874,6 +874,38 @@ _('record the specified user in metadata'), _('USER')), ] +def _deprecatealias(oldalias, newalias): + '''Deprecates an alias for a command in favour of another + + Creates a new entry in the command table for the old alias. It creates a + wrapper that has its synopsis set to show that is has been deprecated. + The documentation will be replace with a pointer to the new alias. + If a user invokes the command a deprecation warning will be printed and + the command of the *new* alias will be invoked. + + This function is loosely based on the extensions.wrapcommand function. + ''' + aliases, entry = cmdutil.findcmd(newalias, cmdtable) + for alias, e in cmdtable.iteritems(): + if e is entry: + break + + synopsis = '(DEPRECATED)' + if len(entry) > 2: + fn, opts, _syn = entry + else: + fn, opts, = entry + deprecationwarning = _('%s have been deprecated in favor of %s\n' % ( + oldalias, newalias)) + def newfn(*args, **kwargs): + ui = args[0] + ui.warn(deprecationwarning) + util.checksignature(fn)(*args, **kwargs) + newfn.__doc__ = deprecationwarning + cmdwrapper = command(oldalias, opts, synopsis) + cmdwrapper(newfn) + + @command('debugrecordpruneparents', [], '') def cmddebugrecordpruneparents(ui, repo): """add parents data to prune markers when possible