go-deb/main.go

102 lines
1.9 KiB
Go

package main
import (
"embed"
"os"
"path/filepath"
"go.wit.com/gui"
"go.wit.com/lib/fhelp"
"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
func main() {
me = new(mainType)
goSrc, hasWork, err := fhelp.DetermineGoPath()
if err != nil {
badExit(err)
}
log.Info("GO src path", goSrc, "go.work is", hasWork)
me.goSrc = goSrc
me.hasWork = hasWork
// set the go src path
os.Setenv("REPO_WORK_PATH", 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()
me.myGui = gui.New()
if !argv.Auto {
me.myGui.InitEmbed(resources)
}
me.myGui.Default()
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)
}
me.basicWindow.Show()
// go will sit here until the window exits
gui.Watchdog()
os.Exit(0)
}