def _get_cmd_tree(subcmds):
    """Convert flat list of subcmd objects into hierarchical dictionary
    {'command name': {'subcommand name 1': subcmd1, 'subcommand name 2': subcmd2}}"""
    cmds = {}
    for sub_cmd in subcmds:
        cmd_dict = cmds.setdefault(sub_cmd.cmd, {})
        cmd_dict[sub_cmd.name] = sub_cmd
    return cmds