summaryrefslogtreecommitdiff
path: root/main.go
blob: 2f20bcdfe8ad53dafcbba2c42784fb9a77d1556b (plain)
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
package main

import (
	"os"

	"go.wit.com/dev/alexflint/arg"
	"go.wit.com/lib/protobuf/forgepb"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

// sent via -ldflags
var VERSION string
var BUILDTIME string

var pp *arg.Parser
var forge *forgepb.Forge
var check *gitpb.Repo

func main() {
	log.Info("go-clean version", VERSION, "built on", BUILDTIME)
	pp = arg.MustParse(&argv)

	// for very new users or users unfamilar with the command line, this may help them
	if argv.Repo == "help" || argv.Repo == "?" {
		pp.WriteHelp(os.Stdout)
		os.Exit(0)
	}
	if argv.Repo == "version" {
		log.Info(argv.Version())
		os.Exit(0)
	}

	// load the ~/.config/forge/ config
	// this lets you configure repos you have read/write access too
	forge = forgepb.Init()

	check = forge.Repos.FindByGoPath(argv.Repo)
	if check == nil {
		log.Info("need to go-clone", argv.Repo)
		return
	}
	log.Info("already have", argv.Repo)

	log.Info("go src dir", forge.GetGoSrc())
	// re-create go.sum and go.mod
	check.RedoGoMod()
	deps := check.GoDeps.SortByGoPath()
	for deps.Scan() {
		depRepo := deps.Next()
		log.Info("download:", depRepo.GoPath)
		_, err := forge.Build(depRepo.GoPath)
	}
	okExit("skipping build of " + argv.Repo)
}

func okExit(thing string) {
	log.Info(thing, "ok")
	log.Info("Finished clone on", check.GetGoPath(), "ok")
	os.Exit(0)
}

func badExit(err error) {
	log.Info("Total repositories:", forge.Repos.Len())
	log.Info("Finished go-clean with error", err, forge.GetGoSrc())
	os.Exit(-1)
}