Revision 451a7992 kamaki/cli/__init__.py
b/kamaki/cli/__init__.py | ||
---|---|---|
112 | 112 |
|
113 | 113 |
def command(cmd_tree, prefix='', descedants_depth=1): |
114 | 114 |
"""Load a class as a command |
115 |
spec_cmd0_cmd1 will be command spec cmd0 |
|
116 |
@cmd_tree is initialized in cmd_spec file and is the structure |
|
115 |
e.g. spec_cmd0_cmd1 will be command spec cmd0 |
|
116 |
|
|
117 |
:param cmd_tree: is initialized in cmd_spec file and is the structure |
|
117 | 118 |
where commands are loaded. Var name should be _commands |
118 |
@param prefix if given, load only commands prefixed with prefix,
|
|
119 |
@param descedants_depth is the depth of the tree descedants of the
|
|
119 |
:param prefix: if given, load only commands prefixed with prefix,
|
|
120 |
:param descedants_depth: is the depth of the tree descedants of the
|
|
120 | 121 |
prefix command. It is used ONLY if prefix and if prefix is not |
121 | 122 |
a terminal command |
123 |
|
|
124 |
:returns: the specified class object |
|
122 | 125 |
""" |
123 | 126 |
|
124 | 127 |
def wrap(cls): |
128 |
global kloger |
|
125 | 129 |
cls_name = cls.__name__ |
126 | 130 |
|
127 | 131 |
if not cmd_tree: |
128 | 132 |
if _debug: |
129 |
print('Warning: command %s found but not loaded' % cls_name)
|
|
133 |
kloger.warning('command %s found but not loaded' % cls_name)
|
|
130 | 134 |
return cls |
131 | 135 |
|
132 | 136 |
name_terms = cls_name.split('_') |
133 | 137 |
if not _update_best_match(name_terms, prefix): |
134 | 138 |
if _debug: |
135 |
print('Warning: %s failed to update_best_match' % cls_name)
|
|
139 |
kloger.warning('%s failed to update_best_match' % cls_name)
|
|
136 | 140 |
return None |
137 | 141 |
|
138 | 142 |
global _best_match |
... | ... | |
142 | 146 |
if not cmd_tree.has_command(partial): # add partial path |
143 | 147 |
cmd_tree.add_command(partial) |
144 | 148 |
if _debug: |
145 |
print('Warning: %s failed max_len test' % cls_name)
|
|
149 |
kloger.warning('%s failed max_len test' % cls_name)
|
|
146 | 150 |
return None |
147 | 151 |
|
148 | 152 |
cls.description, sep, cls.long_description\ |
Also available in: Unified diff