summaryrefslogtreecommitdiff
path: root/main.go
blob: 066d374c73fc97296f13e38713923b5f4cf08149 (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
68
69
70
71
72
package main

import (
	"embed"

	"go.wit.com/lib/config"
	"go.wit.com/lib/gui/prep"
	"go.wit.com/lib/protobuf/zoopb"
	"go.wit.com/log"
)

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

// used for shell auto completion
var ARGNAME string = "mirrors" // todo: get this from $0 ?

//go:embed resources/*
var resources embed.FS

func main() {
	me = new(mainType)
	me.sh = prep.Bash3(&argv) // add support for bash autocomplete with go-arg

	me.mirrorsDir = "/home/mirrors/wit"

	// read in protobuf file
	me.pb = zoopb.NewPackages()
	me.pb.Filename = "/home/mirrors/mirrors.wit.com.pb"
	if err := me.pb.Load(); err != nil {
		if argv.Force {
			config.Save(me.pb)
		} else {
			me.sh.BadExit("no config found. use --force to create one", err)
		}
	}

	if me.sh.Cmd == "" {
		// default behavior when no argv
		s := log.Sprintf("You have %d packages in %s", me.pb.Len(), me.mirrorsDir)
		me.sh.GoodExit(s)
	}

	// default handling of argv subcommands
	var s string
	var err error
	if argv.Incoming != nil {
		s, err = doIncoming(me.pb)
	}

	if argv.Walk != nil {
		s, err = doWalk()
	}

	if argv.List != nil {
		s, err = doList()
	}

	if argv.Update != nil {
		err = doDistro()
	}

	if argv.MakeDists != nil {
		s, err = doMakeDists("/home/mirrors/wit")
	}

	if err != nil {
		me.sh.BadExit(s, err)
	}
	me.sh.GoodExit(s)
}