summaryrefslogtreecommitdiff
path: root/main.go
blob: 205e90f7faba44cfc224b3fe7a0c5d1d40631fba (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main

import (
	"embed"
	"os"
	"path/filepath"
	"time"

	"go.wit.com/dev/alexflint/arg"
	"go.wit.com/lib/fhelp"
	"go.wit.com/lib/gui/prep"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/forgepb"
	"go.wit.com/log"
)

// sent from -ldflags
var VERSION string
var DATE string

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

var ARGNAME string = "go-deb"
var argv args

func main() {
	me = new(mainType)
	prep.Bash(ARGNAME, argv.DoAutoComplete) // this line should be:  prep.Bash(argv)
	me.myGui = prep.Gui()                   // prepares the GUI package for go-args
	me.pp = arg.MustParse(&argv)

	if err := fhelp.ConfigureENV(); err != nil {
		badExit(err)
	}
	me.goSrc = os.Getenv("FORGE_GOSRC")
	if os.Getenv("FORGE_GOWORK") == "true" {
		me.hasWork = true
	}
	log.Info("GO src path", me.goSrc, "go.work is", me.hasWork)

	// set the go src path
	os.Setenv("REPO_WORK_PATH", me.goSrc)

	if argv.Forge != "" {
		me.forge = forgepb.Init()

		me.repo = me.forge.Repos.FindByFullPath(argv.Forge)
		if me.repo == nil {
			log.Info("repo not found", argv.Forge)
			me.repo = me.forge.FindByGoPath(argv.Forge)
		}
		if me.repo == nil {
			log.Info("forge failure. repo not found", argv.Forge)
			os.Exit(-1)
		}
		log.Info("found repo", me.repo.GetGoPath())
	}
	// build()
	if argv.Show != nil {
		log.Info("todo: show", me.repo.GetGoPath())
		okExit("")
	}

	me.basicWindow = makebasicWindow()

	// figure out where we are working from
	// os.Chdir to that directory
	var debpath string
	if me.repo == nil {
		os.Setenv("GO_DEB_CUSTOM", "true")
		debpath, _ = os.Getwd()
	} else {
		debpath = me.repo.GetFullPath()
	}
	_, basename := filepath.Split(debpath)
	me.goPath = basename
	os.Chdir(debpath)

	// scan the repo
	me.cBox.addRepo()

	// look for a 'config' file in the repo
	if me.cBox.readControlFile() == nil {
		log.Warn("scan worked")
	} else {
		log.Warn("scan failed")
	}
	me.cBox.computeControlValues()
	// verify the values for the package

	if argv.Auto {
		shell.TestTerminalColor()
		// basicWindow.Show() // broken gui package. convert to protobuf
		if ok, err := me.cBox.buildPackage(); ok {
			log.Info("build worked")
		} else {
			log.Warn("build failed:", err)
			os.Exit(-1)
		}
		os.Exit(0)
	}

	if argv.Gui != nil {
		// only load teh toolkit if you get this far
		me.myGui.Start() // loads the GUI toolkit
		me.basicWindow.Show()
		debug()
	}
	log.Info("go-deb: nothing to do in argv")
	os.Exit(0)
}

func debug() {
	time.Sleep(2 * time.Second)
	for {
		log.Info("idle loop() todo: could check for things here")
		time.Sleep(90 * time.Second)
	}
}