-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
83 lines (70 loc) · 1.68 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"log"
"os"
"github.com/jamesjarvis/go-deps/host"
"github.com/jamesjarvis/go-deps/module"
"github.com/urfave/cli/v2"
)
const (
moduleFlag = "module"
versionFlag = "version"
thirdPartyFlag = "third_party"
)
// This binary will accept a module name and optionally a semver or commit hash, and will add this module to a BUILD file.
func main() {
app := &cli.App{
Name: "please-go-get",
Usage: "Add a Go Module to an existing Please Monorepo",
Flags: []cli.Flag{
&cli.StringFlag{
Name: moduleFlag,
Aliases: []string{"m"},
Usage: "Module to add",
Required: true,
},
&cli.StringFlag{
Name: versionFlag,
Aliases: []string{"v"},
Usage: "Version of the module to add",
},
&cli.StringFlag{
Name: thirdPartyFlag,
DefaultText: "third_party/go",
Usage: "The third party folder to write rules to",
},
},
Action: func(ctx *cli.Context) error {
fmt.Println("Please Go Get v0.0.1")
alreadyExists, err := host.CreateGoMod(ctx.Context)
if err != nil {
return err
}
if !alreadyExists {
defer host.TearDownGoMod(ctx.Context)
}
m := &module.Module{
Path: ctx.String(moduleFlag),
Version: ctx.String(versionFlag),
}
fmt.Printf("So, you want to add %q?\n", m.String())
err = m.Download(ctx.Context)
if err != nil {
return err
}
_, err = m.GetDependenciesRecursively(ctx.Context)
if err != nil {
return err
}
module.GlobalCache.Sync()
module.GlobalCache.Print()
return module.GlobalCache.ExportBuildRules(ctx.String(thirdPartyFlag))
},
}
app.EnableBashCompletion = true
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}