def command()

in nubia/internal/typing/__init__.py [0:0]


def command(name_or_function=None, help=None, aliases=None, exclusive_arguments=None):
    """
    Annotation decorator to specify that a function or method is a command
    that should be exported by nubia

    Check the module documentation for more info and tests.py in this module
    for usage examples
    """

    def decorator(function, name=None):
        is_supercommand = isclass(name_or_function)
        exclusive_arguments_ = _normalize_exclusive_arguments(exclusive_arguments)
        _validate_exclusive_arguments(function, exclusive_arguments_)

        _init_attr(function, "__command", {})
        if name:
            function.__command["name"] = name
        else:
            function.__command["name"] = (
                transform_name(function.__name__)
                if not is_supercommand
                else transform_class_name(function.__name__)
            )
        function.__command["help"] = help
        function.__command["aliases"] = aliases or []
        function.__command["exclusive_arguments"] = exclusive_arguments_
        return function

    # Allows the decorator to be used directly (`@command`) or as a
    # function call (`@command()`)
    if callable(name_or_function):
        function = name_or_function
        return decorator(function)
    else:
        name = name_or_function
        return partial(decorator, name=name)