Show More
@@ -173,11 +173,17 b' class magic_arguments(ArgDecorator):' | |||||
173 | return func |
|
173 | return func | |
174 |
|
174 | |||
175 |
|
175 | |||
176 |
class |
|
176 | class ArgMethodWrapper(ArgDecorator): | |
177 | """ Store arguments and keywords to pass to add_argument(). |
|
177 | ||
|
178 | """ | |||
|
179 | Base class to define a wrapper for ArgumentParser method. | |||
|
180 | ||||
|
181 | Child class must define either `_method_name` or `add_to_parser`. | |||
178 |
|
182 | |||
179 | Instances also serve to decorate command methods. |
|
|||
180 | """ |
|
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. |
|
196 | getattr(parser, self._method_name)(*self.args, **self.kwds) | |
191 | return None |
|
197 | return None | |
192 |
|
198 | |||
193 |
|
199 | |||
194 |
class |
|
200 | class argument(ArgMethodWrapper): | |
195 |
""" Store arguments and keywords to pass to |
|
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): |
|
207 | ||
204 | """ Add this object's information to the parser. |
|
208 | class defaults(ArgMethodWrapper): | |
|
209 | """ Store arguments and keywords to pass to set_defaults(). | |||
|
210 | ||||
|
211 | Instances also serve to decorate command methods. | |||
205 |
|
|
212 | """ | |
206 | if group is not None: |
|
213 | _method_name = 'set_defaults' | |
207 | parser = group |
|
|||
208 | parser.set_defaults(*self.args, **self.kwds) |
|
|||
209 | return None |
|
|||
210 |
|
214 | |||
211 |
|
215 | |||
212 |
class argument_group(Arg |
|
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