-
Notifications
You must be signed in to change notification settings - Fork 271
Closed
Labels
Description
Describe the feature
Currently in my magefile.go:
func runf(cmd string, args ...string) mg.Fn {
return newRunfn(func() error {
return sh.Run(cmd, args...)
}, "Run", args...)
}
func runfv(cmd string, args ...string) mg.Fn {
return newRunfn(func() error {
return sh.Run(cmd, args...)
}, "RunV", args...)
}
type runfn struct {
name string
id string
f func() error
}
func newRunfn(f func() error, name string, args ...string) runfn {
id, err := json.Marshal(args)
if err != nil {
panic(err)
}
return runfn{
name: name,
id: string(id),
f: f,
}
}
func (fn runfn) Name() string {
return fn.name
}
func (fn runfn) ID() string {
return fn.id
}
func (fn runfn) Run(ctx context.Context) error {
return fn.f()
}Used as such:
func Test() {
mg.Deps(
runf("go", "test", "-tags", "test", "./..."),
runfv("docker-compose", "pull"),
)
}I think it would be useful to have this in the sh or mg package, probably as RunF and RunFV and perhaps more.
What problem does this feature address?
It lets you put shell commands directly in mg.Deps calls.
I think it improves readability to avoid the single line functions just calling sh.Run or sh.RunV.