import functools


def subcommand(
    name=None,
    help=None,
):
    """
    A decorator that mark a function / class method a sub command for CLI.

    :type name: str
    :type help: str
    """

    def real_deco(func):
        if name is None:
            func._subcommand_name = func.__name__.replace("_", "-")
        else:
            func._subcommand_name = name.replace("_", "-")
        func._subcommand_help = help
        func._is_subcommand = True

        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            res = func(*args, **kwargs)
            return res

        return wrapper

    return real_deco