pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.41k stars 369 forks source link

Is there support for making invoke.yaml context settings cli flags? #984

Open red8888 opened 10 months ago

red8888 commented 10 months ago

CLI frameworks like Cobra work like this, your params aren't just settable as cli flags, but also in a config file.

It appears pyinvoke separates the two.

I can define cli flags on the individual funcs

@task
def show_config(ctx: Context, myflag: str, myotherflag: str):

But "configuration" is an entirely separate thing: https://docs.pyinvoke.org/en/latest/concepts/configuration.html

Is it at all possible to define flags as part of configuration like this:

ns = Collection()
col = Collection.from_module("my_module")
col.configure({"myflag": "default value", "myotherflag": "default value"})
ns.add_collection(col)

@task
def show_config(ctx: Context) # Have the decorator magically inject myflag and myotherflag from config

Is there a way I could add this myself if its not supported?

I looks like I can't expand a dict like this right?

d = dict(p1=1, p2=2)
@task
def my_cmd(ctx: Context, **d):