##// END OF EJS Templates
Refactor magic_arguments.py
Takafumi Arakaki -
Show More
@@ -173,11 +173,17 b' class magic_arguments(ArgDecorator):'
173 return func
173 return func
174
174
175
175
176 class argument(ArgDecorator):
176 class ArgMethodWrapper(ArgDecorator):
177 """ Store arguments and keywords to pass to add_argument().
178
177
179 Instances also serve to decorate command methods.
180 """
178 """
179 Base class to define a wrapper for ArgumentParser method.
180
181 Child class must define either `_method_name` or `add_to_parser`.
182
183 """
184
185 _method_name = None
186
181 def __init__(self, *args, **kwds):
187 def __init__(self, *args, **kwds):
182 self.args = args
188 self.args = args
183 self.kwds = kwds
189 self.kwds = kwds
@@ -187,36 +193,31 b' class argument(ArgDecorator):'
187 """
193 """
188 if group is not None:
194 if group is not None:
189 parser = group
195 parser = group
190 parser.add_argument(*self.args, **self.kwds)
196 getattr(parser, self._method_name)(*self.args, **self.kwds)
191 return None
197 return None
192
198
193
199
194 class defaults(ArgDecorator):
200 class argument(ArgMethodWrapper):
195 """ Store arguments and keywords to pass to set_defaults().
201 """ Store arguments and keywords to pass to add_argument().
196
202
197 Instances also serve to decorate command methods.
203 Instances also serve to decorate command methods.
198 """
204 """
199 def __init__(self, *args, **kwds):
205 _method_name = 'add_argument'
200 self.args = args
201 self.kwds = kwds
202
206
203 def add_to_parser(self, parser, group):
204 """ Add this object's information to the parser.
205 """
206 if group is not None:
207 parser = group
208 parser.set_defaults(*self.args, **self.kwds)
209 return None
210
207
208 class defaults(ArgMethodWrapper):
209 """ Store arguments and keywords to pass to set_defaults().
211
210
212 class argument_group(ArgDecorator):
211 Instances also serve to decorate command methods.
212 """
213 _method_name = 'set_defaults'
214
215
216 class argument_group(ArgMethodWrapper):
213 """ Store arguments and keywords to pass to add_argument_group().
217 """ Store arguments and keywords to pass to add_argument_group().
214
218
215 Instances also serve to decorate command methods.
219 Instances also serve to decorate command methods.
216 """
220 """
217 def __init__(self, *args, **kwds):
218 self.args = args
219 self.kwds = kwds
220
221
221 def add_to_parser(self, parser, group):
222 def add_to_parser(self, parser, group):
222 """ Add this object's information to the parser.
223 """ Add this object's information to the parser.
General Comments 0
You need to be logged in to leave comments. Login now