magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.12k stars 251 forks source link

Enhancement: Variadic support in mg.F #401

Closed perj closed 2 years ago

perj commented 2 years ago

Describe the feature I would like mg.F to support variadic functions.

What problem does this feature address? The main use case would be to pass sh.Run to it, as such: mg.F(sh.Run, "go", "test", "./...") I think this should be possible with some work. mg.F(sh.Run, "go", []string{"test", "./..."}) would also be ok, or another function instead of mg.F.

Right now there's a lot of single-line functions that need to be added that are then passed to mg.Deps. As pointed out in #400, it's possible to use inline function literals for this, but those are also quite verbose. Also they might run the same command multiple times, as the arguments and actual function are not part of the deps check for those literals.

Having sh.Run directly in mg.Deps improve readability and simplifies the magefile writing.

Additional context This occurred to me during the discussion in #400 where I had a different syntax for the same thing.