Return a list of Argument objects representing this task's signature. :param bool ignore_unknown_help: Controls whether unknown help flags cause errors. See the config option by the same name for details. .. versionadded:: 1.0 .. versionchan
(
self, ignore_unknown_help: Optional[bool] = None
)
| 237 | return opts |
| 238 | |
| 239 | def get_arguments( |
| 240 | self, ignore_unknown_help: Optional[bool] = None |
| 241 | ) -> List[Argument]: |
| 242 | """ |
| 243 | Return a list of Argument objects representing this task's signature. |
| 244 | |
| 245 | :param bool ignore_unknown_help: |
| 246 | Controls whether unknown help flags cause errors. See the config |
| 247 | option by the same name for details. |
| 248 | |
| 249 | .. versionadded:: 1.0 |
| 250 | .. versionchanged:: 1.7 |
| 251 | Added the ``ignore_unknown_help`` kwarg. |
| 252 | """ |
| 253 | # Core argspec |
| 254 | sig = self.argspec(self.body) |
| 255 | # Prime the list of all already-taken names (mostly for help in |
| 256 | # choosing auto shortflags) |
| 257 | taken_names = set(sig.parameters.keys()) |
| 258 | # Build arg list (arg_opts will take care of setting up shortnames, |
| 259 | # etc) |
| 260 | args = [] |
| 261 | for param in sig.parameters.values(): |
| 262 | new_arg = Argument( |
| 263 | **self.arg_opts(param.name, param.default, taken_names) |
| 264 | ) |
| 265 | args.append(new_arg) |
| 266 | # Update taken_names list with new argument's full name list |
| 267 | # (which may include new shortflags) so subsequent Argument |
| 268 | # creation knows what's taken. |
| 269 | taken_names.update(set(new_arg.names)) |
| 270 | # If any values were leftover after consuming a 'help' dict, it implies |
| 271 | # the user messed up & had a typo or similar. Let's explode. |
| 272 | if self.help and not ignore_unknown_help: |
| 273 | raise ValueError( |
| 274 | "Help field was set for param(s) that don't exist: {}".format( |
| 275 | list(self.help.keys()) |
| 276 | ) |
| 277 | ) |
| 278 | # Now we need to ensure positionals end up in the front of the list, in |
| 279 | # order given in self.positionals, so that when Context consumes them, |
| 280 | # this order is preserved. |
| 281 | for posarg in reversed(list(self.positional)): |
| 282 | for i, arg in enumerate(args): |
| 283 | if arg.name == posarg: |
| 284 | args.insert(0, args.pop(i)) |
| 285 | break |
| 286 | return args |
| 287 | |
| 288 | |
| 289 | def task(*args: Any, **kwargs: Any) -> Callable: |
no test coverage detected