<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _build_cmd_tree(self, cmd_cls, cmd_name=None):
 """ Build a tree of commands. :param cmd_cls: The Command class or object to start with. :param cmd_name: Hard-coded name of the command (can be None for auto-detection) :returns: A tree structure represented as tuple ``(cmd_obj, cmd_name, children)`` Where ``cmd_obj`` is a Command instance, cmd_name is its name, if any (it might be None) and ``children`` is a tuple of identical tuples. Note that command name auto-detection relies on :meth:`guacamole.recipes.cmd.Command.get_cmd_name()`. Let's look at a simple git-like example:: (None, '<git>', ( ('log', <git_log>, ()), ('stash', <git_stash>, ( ('list', <git_stash_list>, ()),),),),) """

        if isinstance(cmd_cls, type):
            cmd_obj = cmd_cls()
        else:
            cmd_obj = cmd_cls
        if cmd_name is None:
            cmd_name = cmd_obj.get_cmd_name()
        return cmd_tree_node(cmd_name, cmd_obj, tuple([
            self._build_cmd_tree(subcmd_cls, subcmd_name)
            for subcmd_name, subcmd_cls in cmd_obj.get_sub_commands()]))