go-deb/main.go

108 lines
2.0 KiB
Go
Raw Permalink Normal View History

2024-02-11 01:00:05 -06:00
package main
import (
"embed"
"os"
"path/filepath"
2025-02-22 07:35:37 -06:00
"go.wit.com/dev/alexflint/arg"
2024-02-11 01:00:05 -06:00
"go.wit.com/gui"
2025-01-18 07:29:44 -06:00
"go.wit.com/lib/fhelp"
2024-03-01 07:44:02 -06:00
"go.wit.com/lib/gui/shell"
2024-12-01 00:48:07 -06:00
"go.wit.com/lib/protobuf/forgepb"
2024-02-11 01:00:05 -06:00
"go.wit.com/log"
)
2024-11-07 07:03:13 -06:00
// sent from -ldflags
var VERSION string
2024-11-15 10:51:45 -06:00
var DATE string
2024-11-07 07:03:13 -06:00
//go:embed resources/*
var resources embed.FS
2025-02-22 07:35:37 -06:00
var argv args
2024-02-11 01:00:05 -06:00
func main() {
2025-01-18 07:29:44 -06:00
me = new(mainType)
2025-02-22 07:35:37 -06:00
gui.InitArg()
arg.MustParse(&argv)
2025-01-18 07:29:44 -06:00
goSrc, hasWork, err := fhelp.DetermineGoPath()
if err != nil {
badExit(err)
}
2025-01-18 07:29:44 -06:00
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()
2024-12-01 00:48:07 -06:00
2025-01-18 07:29:44 -06:00
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())
2024-12-01 00:48:07 -06:00
}
// build()
2025-01-18 07:29:44 -06:00
me.myGui = gui.New()
2024-11-16 09:49:49 -06:00
if !argv.Auto {
2025-01-18 07:29:44 -06:00
me.myGui.InitEmbed(resources)
}
2025-01-18 07:29:44 -06:00
me.myGui.Default()
2024-02-11 01:00:05 -06:00
2025-01-18 07:29:44 -06:00
me.basicWindow = makebasicWindow()
2024-02-11 01:00:05 -06:00
2025-01-18 07:29:44 -06:00
// figure out where we are working from
// os.Chdir to that directory
2024-11-16 09:49:49 -06:00
var debpath string
2025-01-18 07:29:44 -06:00
if me.repo == nil {
2024-11-16 09:49:49 -06:00
os.Setenv("GO_DEB_CUSTOM", "true")
debpath, _ = os.Getwd()
} else {
2025-01-18 07:29:44 -06:00
debpath = me.repo.GetFullPath()
2024-11-16 09:49:49 -06:00
}
2025-01-18 07:29:44 -06:00
_, basename := filepath.Split(debpath)
me.goPath = basename
2024-11-16 09:49:49 -06:00
os.Chdir(debpath)
// scan the repo
2025-01-18 07:29:44 -06:00
me.cBox.addRepo()
2024-02-20 23:13:26 -06:00
// look for a 'config' file in the repo
2025-01-18 07:29:44 -06:00
if me.cBox.readControlFile() == nil {
log.Warn("scan worked")
} else {
log.Warn("scan failed")
}
2025-01-18 07:29:44 -06:00
me.cBox.computeControlValues()
// verify the values for the package
2024-11-16 09:49:49 -06:00
if argv.Auto {
2024-02-23 22:07:13 -06:00
shell.TestTerminalColor()
// basicWindow.Show() // broken gui package. convert to protobuf
2025-01-18 07:29:44 -06:00
if ok, err := me.cBox.buildPackage(); ok {
2024-11-06 17:51:49 -06:00
log.Info("build worked")
} else {
2024-03-01 07:44:02 -06:00
log.Warn("build failed:", err)
2024-02-20 23:13:26 -06:00
os.Exit(-1)
}
os.Exit(0)
2024-02-11 01:00:05 -06:00
}
2025-01-18 07:29:44 -06:00
me.basicWindow.Show()
// go will sit here until the window exits
gui.Watchdog()
os.Exit(0)
2024-02-11 01:00:05 -06:00
}