Show More
@@ -173,11 +173,17 b' class magic_arguments(ArgDecorator):' | |||
|
173 | 173 | return func |
|
174 | 174 | |
|
175 | 175 | |
|
176 |
class |
|
|
177 | """ Store arguments and keywords to pass to add_argument(). | |
|
176 | class ArgMethodWrapper(ArgDecorator): | |
|
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 | 187 | def __init__(self, *args, **kwds): |
|
182 | 188 | self.args = args |
|
183 | 189 | self.kwds = kwds |
@@ -187,36 +193,31 b' class argument(ArgDecorator):' | |||
|
187 | 193 | """ |
|
188 | 194 | if group is not None: |
|
189 | 195 | parser = group |
|
190 |
parser. |
|
|
196 | getattr(parser, self._method_name)(*self.args, **self.kwds) | |
|
191 | 197 | return None |
|
192 | 198 | |
|
193 | 199 | |
|
194 |
class |
|
|
195 |
""" Store arguments and keywords to pass to |
|
|
200 | class argument(ArgMethodWrapper): | |
|
201 | """ Store arguments and keywords to pass to add_argument(). | |
|
196 | 202 | |
|
197 | 203 | Instances also serve to decorate command methods. |
|
198 | 204 | """ |
|
199 | def __init__(self, *args, **kwds): | |
|
200 | self.args = args | |
|
201 | self.kwds = kwds | |
|
205 | _method_name = 'add_argument' | |
|
202 | 206 | |
|
203 | def add_to_parser(self, parser, group): | |
|
204 | """ Add this object's information to the parser. | |
|
207 | ||
|
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: | |
|
207 | parser = group | |
|
208 | parser.set_defaults(*self.args, **self.kwds) | |
|
209 | return None | |
|
213 | _method_name = 'set_defaults' | |
|
210 | 214 | |
|
211 | 215 | |
|
212 |
class argument_group(Arg |
|
|
216 | class argument_group(ArgMethodWrapper): | |
|
213 | 217 | """ Store arguments and keywords to pass to add_argument_group(). |
|
214 | 218 | |
|
215 | 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 | 222 | def add_to_parser(self, parser, group): |
|
222 | 223 | """ Add this object's information to the parser. |
General Comments 0
You need to be logged in to leave comments.
Login now