Fetch action in callable attributes which and commands

    Callable must have their attribute 'command' set to True to
    be recognised by this lookup.

    Please consider using the decorator ``@cmd`` to declare your
    subcommands in classes for instance.

def get_obj_subcmds(obj):
    """Fetch action in callable attributes which and commands

    Callable must have their attribute 'command' set to True to
    be recognised by this lookup.

    Please consider using the decorator ``@cmd`` to declare your
    subcommands in classes for instance.

    """
    subcmds = []
    for label in dir(obj.__class__):
        if label.startswith("_"):
            continue
        if isinstance(getattr(obj.__class__, label, False), property):
            continue
        rvalue = getattr(obj, label)
        if not callable(rvalue) or not is_cmd(rvalue):
            continue
        if isinstance(obj, types.MethodType) and \
               label in ("im_func", "im_self", "im_class"):
            continue
        ## potential command
        command_name = getattr(rvalue, "command_name",
                               label[:-1] if label.endswith("_") else
                               label)
        subcmds.append((command_name, rvalue))
    return OrderedDict(subcmds)