-
Notifications
You must be signed in to change notification settings - Fork 9
/
rungo.go
32 lines (27 loc) · 1.06 KB
/
rungo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package rungo
import (
"context"
"strings"
"namespacelabs.dev/foundation/internal/git"
"namespacelabs.dev/foundation/internal/localexec"
"namespacelabs.dev/foundation/internal/sdk/golang"
"namespacelabs.dev/foundation/std/pkggraph"
"namespacelabs.dev/foundation/std/tasks"
)
func RunGo(ctx context.Context, loc pkggraph.Location, sdk golang.LocalSDK, args ...string) error {
return tasks.Action("go.run").Arg("dir", loc.Rel()).HumanReadablef("go "+strings.Join(args, " ")).Run(ctx, func(ctx context.Context) error {
var cmd localexec.Command
cmd.Command = golang.GoBin(sdk)
cmd.Args = args
cmd.AdditionalEnv = MakeGoEnv(sdk)
cmd.Dir = loc.Abs()
cmd.Label = "go " + strings.Join(cmd.Args, " ")
return cmd.Run(ctx)
})
}
func MakeGoEnv(sdk golang.LocalSDK) []string {
return append([]string{golang.GoRootEnv(sdk), goPrivate()}, git.NoPromptEnv().Serialize()...)
}