*args and **kwargs support!

Try it!

invoke run mytask these are positional --flag1 keyword!:

invoke myfunc pos args --flag1 hi --flag2 there
('pos', 'args') {'flag1': 'hi', 'flag2': 'there'}

tasks.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from __future__ import print_function
from invoke import task
from pprint import pformat


@task
def myfunc(ctx, *args, **kwargs):
    """
    Note there is a bug where we couldn't do
       def mine(ctx, mypositionalarg, *args, **kwargs):
           pass

    But something is better than nothing :) Search "TODO 531"
    to find the comment describing our options.
    Keyword optional args work but they can be filled by positional args
    (because they're not KEYWORD_ONLY!) so we don't recommend their use.
    """
    print("args: {}".format(args))
    print("kwargs: {}".format(pformat(kwargs)))