[PATCH] commands: use a class as decorator to build table incrementally

Matt Mackall mpm at selenic.com
Wed May 11 12:27:08 CDT 2011


On Wed, 2011-05-11 at 18:13 +0200, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1305097807 -7200
> # Node ID 8b331aca1943f7840591dd3289e55f99ba164375
> # Parent  c97d8485b5fa46c94b8afcfab0cde97629ba4086
> commands: use a class as decorator to build table incrementally
> 
> this allows to define the table entries near the command function

Thanks, we probably should have done something like this years ago.

> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -17,8 +17,134 @@
>  import dagparser, context, simplemerge
>  import random, setdiscovery, treediscovery, dagutil
>  
> +table = {}
> +
> +class command(object):
> +    '''decorator for populating the command table'''
> +    def __init__(self, name, options, synopsis=None):
> +        self.name = name
> +        self.options = options
> +        self.synopsis = synopsis
> +
> +    def __call__(self, func):
> +        if self.synopsis:
> +            table[self.name] = func, self.options, self.synopsis
> +        else:
> +            table[self.name] = func, self.options
> +        return func

Does this want to live in cmdutil for use by extensions?

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list