Marks wrapped callable object as a valid Invoke task. May be called without any parentheses if no extra options need to be specified. Otherwise, the following keyword arguments are allowed in the parenthese'd form: * ``name``: Default name to use when binding to a `.Collection
(*args: Any, **kwargs: Any)
| 287 | |
| 288 | |
| 289 | def task(*args: Any, **kwargs: Any) -> Callable: |
| 290 | """ |
| 291 | Marks wrapped callable object as a valid Invoke task. |
| 292 | |
| 293 | May be called without any parentheses if no extra options need to be |
| 294 | specified. Otherwise, the following keyword arguments are allowed in the |
| 295 | parenthese'd form: |
| 296 | |
| 297 | * ``name``: Default name to use when binding to a `.Collection`. Useful for |
| 298 | avoiding Python namespace issues (i.e. when the desired CLI level name |
| 299 | can't or shouldn't be used as the Python level name.) |
| 300 | * ``aliases``: Specify one or more aliases for this task, allowing it to be |
| 301 | invoked as multiple different names. For example, a task named ``mytask`` |
| 302 | with a simple ``@task`` wrapper may only be invoked as ``"mytask"``. |
| 303 | Changing the decorator to be ``@task(aliases=['myothertask'])`` allows |
| 304 | invocation as ``"mytask"`` *or* ``"myothertask"``. |
| 305 | * ``positional``: Iterable overriding the parser's automatic "args with no |
| 306 | default value are considered positional" behavior. If a list of arg |
| 307 | names, no args besides those named in this iterable will be considered |
| 308 | positional. (This means that an empty list will force all arguments to be |
| 309 | given as explicit flags.) |
| 310 | * ``optional``: Iterable of argument names, declaring those args to |
| 311 | have :ref:`optional values <optional-values>`. Such arguments may be |
| 312 | given as value-taking options (e.g. ``--my-arg=myvalue``, wherein the |
| 313 | task is given ``"myvalue"``) or as Boolean flags (``--my-arg``, resulting |
| 314 | in ``True``). |
| 315 | * ``iterable``: Iterable of argument names, declaring them to :ref:`build |
| 316 | iterable values <iterable-flag-values>`. |
| 317 | * ``incrementable``: Iterable of argument names, declaring them to |
| 318 | :ref:`increment their values <incrementable-flag-values>`. |
| 319 | * ``default``: Boolean option specifying whether this task should be its |
| 320 | collection's default task (i.e. called if the collection's own name is |
| 321 | given.) |
| 322 | * ``auto_shortflags``: Whether or not to automatically create short |
| 323 | flags from task options; defaults to True. |
| 324 | * ``help``: Dict mapping argument names to their help strings. Will be |
| 325 | displayed in ``--help`` output. For arguments containing underscores |
| 326 | (which are transformed into dashes on the CLI by default), either the |
| 327 | dashed or underscored version may be supplied here. |
| 328 | * ``pre``, ``post``: Lists of task objects to execute prior to, or after, |
| 329 | the wrapped task whenever it is executed. |
| 330 | * ``autoprint``: Boolean determining whether to automatically print this |
| 331 | task's return value to standard output when invoked directly via the CLI. |
| 332 | Defaults to False. |
| 333 | * ``klass``: Class to instantiate/return. Defaults to `.Task`. |
| 334 | |
| 335 | If any non-keyword arguments are given, they are taken as the value of the |
| 336 | ``pre`` kwarg for convenience's sake. (It is an error to give both |
| 337 | ``*args`` and ``pre`` at the same time.) |
| 338 | |
| 339 | .. versionadded:: 1.0 |
| 340 | .. versionchanged:: 1.1 |
| 341 | Added the ``klass`` keyword argument. |
| 342 | """ |
| 343 | klass: Type[Task] = kwargs.pop("klass", Task) |
| 344 | # @task -- no options were (probably) given. |
| 345 | if len(args) == 1 and callable(args[0]) and not isinstance(args[0], Task): |
| 346 | return klass(args[0], **kwargs) |
no test coverage detected
searching dependent graphs…