Revision eb46e9a1 kamaki/cli/command_tree/__init__.py

b/kamaki/cli/command_tree/__init__.py
71 71

  
72 72
    @property
73 73
    def is_command(self):
74
        return self.cmd_class is not None and len(self.subcommands) == 0
75

  
76
    @property
77
    def has_description(self):
78
        return len(self.help.strip()) > 0
79

  
80
    @property
81
    def description(self):
82
        return self.help
74
        return len(self.subcommands) == 0 if self.cmd_class else False
83 75

  
84 76
    @property
85 77
    def parent_path(self):
86
        parentpath, sep, name = self.path.rpartition('_')
87
        return parentpath
88

  
89
    def set_class(self, cmd_class):
90
        self.cmd_class = cmd_class
91

  
92
    def get_class(self):
93
        return self.cmd_class
94

  
95
    def has_subname(self, subname):
96
        return subname in self.subcommands
97

  
98
    def get_subnames(self):
99
        return self.subcommands.keys()
100

  
101
    def get_subcommands(self):
102
        return self.subcommands.values()
103

  
104
    def sublen(self):
105
        return len(self.subcommands)
78
        try:
79
            return self.path[self.path.rindex('_') + 1:]
80
        except ValueError:
81
            return ''
106 82

  
107 83
    def parse_out(self, args):
108 84
        cmd = self
......
121 97
            self.name,
122 98
            self.is_command,
123 99
            self.help))
124
        for cmd in self.get_subcommands():
100
        for cmd in self.subcommands.values():
125 101
            cmd.pretty_print(recursive)
126 102

  
127 103

  
......
159 135
                cmd.add_subcmd(new_cmd)
160 136
                cmd = new_cmd
161 137
        if cmd_class:
162
            cmd.set_class(cmd_class)
138
            cmd.cmd_class = cmd_class
163 139
        if description is not None:
164 140
            cmd.help = description
165 141

  
......
205 181
    def get_description(self, path):
206 182
        return self._all_commands[path].help
207 183

  
208
    def set_class(self, path, cmd_class):
209
        self._all_commands[path].set_class(cmd_class)
210

  
211
    def get_class(self, path):
212
        return self._all_commands[path].get_class()
213

  
214 184
    def get_subnames(self, path=None):
215 185
        if path in (None, ''):
216 186
            return self.get_group_names()
217
        return self._all_commands[path].get_subnames()
187
        return self._all_commands[path].subcommands.keys()
218 188

  
219 189
    def get_subcommands(self, path=None):
220
        if path in (None, ''):
221
            return self.get_groups()
222
        return self._all_commands[path].get_subcommands()
190
        return self._all_commands[path].subcommands.values() if (
191
            path) else self.get_groups()
223 192

  
224 193
    def get_parent(self, path):
225 194
        if '_' not in path:

Also available in: Unified diff