-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I guess arguments work now #326
Conversation
Once I figured out that the best UX was also the easiest to program.... I just banged it out. So, yeah, that's the thing. Note it only support string, int, bool, and time.Duration.... is there really anything anyone else needs? Are people really gonna type out an ISO 8601 date or something? in theory I could support any number type, but like.. why? |
Hmm, it occurs to me that I'll need to update mg.Deps to support targets with arguments... probably will do some reflection magic like
I could probably do This hopefully would also fix the problem people have right now with trying to pass closures to mg.Deps. |
This is a awesome, early Christmas present 💙
Most of the time the minimal solution is the way to go, sometimes we tend to “overthink“ problems 😄 Going to use the branch to play around with it in my projects. |
To be clear, this does support multiple targets each with their distinct args being passed on the cli. |
mg.Deps now accepts an mg.Fn interface, which can let you pass your own function - usually these will be created by mg.F(func, arg1, arg2...) but you could in theory implement your own mg.Fn (but hopefully you won't have to) |
func Say(something string) {
fmt.Println(something)
}
func Talk() {
// this will Do The Right Thing
// which is to say, it'll run Say("hi!") exactly once and Say("bye!") exactly once
mg.Deps(mg.F(Say, "hi!"), mg.F(Say, "bye!"), mg.F(Say, "hi!"))
} you can also do it this way, which might be more clear: hi := mg.F(Say, "hi!")
bye := mg.F(Say, "bye!")
mg.Deps(hi, bye, hi) (of course, you'd never actually pass the same dependency twice to mg.Deps because it won't run the second one, by definition) |
References #24 |
So, this works now:
Please test with
go get github.com/magefile/mage@nargs
Note: only supports int, string, bool, and time.Duration as arg types. Let me know if there are other types that are necessary.