Decorate a callable to replace it with a manufactured command
    class.

    Extends the interface of ``CommandDecorator``, allowing the same
    ``cmd`` to be used as a decorator or as a decorator factory::

        @cmd(root=True)
        def build():
            ...

        @build.register
        @cmd
        def deploy():
            ...

    Further enables composition of configuration, for example via
    partials, as helpers.

def cmd(*args, **kwargs):
    """Decorate a callable to replace it with a manufactured command
    class.

    Extends the interface of ``CommandDecorator``, allowing the same
    ``cmd`` to be used as a decorator or as a decorator factory::

        @cmd(root=True)
        def build():
            ...

        @build.register
        @cmd
        def deploy():
            ...

    Further enables composition of configuration, for example via
    partials, as helpers.

    """
    try:
        (first, *remainder) = args
    except ValueError:
        pass
    else:
        if callable(first):
            return CommandDecorator(*remainder, **kwargs)(first)

    return CommandDecorator(*args, **kwargs)