@@ -133,7 +133,7 @@ def __init__(self):
133
133
self ._command_info = namedtuple (
134
134
'_COMMAND_INFO' , ['name' , 'callable' , 'category' ])
135
135
136
- def command (self , command_name , category = None ):
136
+ def command (self , command_name = None , category = None ):
137
137
"""Decorator that marks a function as a 'command' which can be invoked with
138
138
arguments from the command line. e.g.:
139
139
@@ -145,15 +145,23 @@ def Hi(name, title='Mr.'):
145
145
146
146
python something.py greet --name=Nick --title=Dr.
147
147
148
+ If 'command_name' is not specified, defaults to function name.
149
+
148
150
If 'category' is specified, commands with the same category are grouped
149
151
together when listing all available commands.
150
152
"""
151
- def command_decorator (cmd_fn ):
152
- self ._all_commands [command_name ] = cmd_fn
153
+ def command_decorator (cmd_fn , cmd_fn_name = None ):
154
+ final_name = cmd_fn_name or command_name or cmd_fn .func_name
155
+ self ._all_commands [final_name ] = cmd_fn
153
156
self ._command_list .append (
154
- self ._command_info (command_name , cmd_fn , category ))
157
+ self ._command_info (final_name , cmd_fn , category ))
155
158
return cmd_fn
156
159
160
+ # Handle no command_name case.
161
+ if callable (command_name ):
162
+ cmd_func = command_name
163
+ return command_decorator (cmd_func , cmd_func .func_name )
164
+
157
165
return command_decorator
158
166
159
167
def SetOptions (self ,
0 commit comments