summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go105
1 files changed, 40 insertions, 65 deletions
diff --git a/main.go b/main.go
index dd5109c..9f62d3f 100644
--- a/main.go
+++ b/main.go
@@ -6,10 +6,8 @@ import (
"path/filepath"
"go.wit.com/gui"
- "go.wit.com/lib/debugger"
- "go.wit.com/lib/gadgets"
+ "go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
- "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
@@ -18,91 +16,76 @@ import (
var VERSION string
var DATE string
-// This is the beginning of the binary tree of GUI widgets
-var myGui *gui.Node
-
-// this scans in the repos
-var forge *forgepb.Forge
-var repo *gitpb.Repo
-
-var cBox *controlBox
-
-// this is a basic window. the user can open and close it
-var basicWindow *gadgets.BasicWindow
-
//go:embed resources/*
var resources embed.FS
func main() {
- if argv.Repo == "" {
- log.Info("You need to tell me what repo you want to work on")
- println("")
- println("go-deb --repo go.wit.com/apps/helloworld")
- os.Exit(0)
+ me = new(mainType)
+
+ goSrc, hasWork, err := fhelp.DetermineGoPath()
+ if err != nil {
+ badExit(err)
}
- forge = forgepb.Init()
- os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())
+ 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()
- repo = forge.FindByGoPath(argv.Repo)
- if repo == nil {
- log.Info("repo not found. you need to clone", argv.Repo)
- os.Exit(-1)
+ 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())
}
- log.Info("found repo", argv.Repo)
// build()
- myGui = gui.New()
+ me.myGui = gui.New()
if !argv.Auto {
- myGui.InitEmbed(resources)
+ me.myGui.InitEmbed(resources)
}
- myGui.Default()
+ me.myGui.Default()
- basicWindow = makebasicWindow()
+ me.basicWindow = makebasicWindow()
- // todo: add the go.work file logic here
- homeDir, _ := os.UserHomeDir()
+ // figure out where we are working from
+ // os.Chdir to that directory
var debpath string
- if argv.Repo == "." {
+ if me.repo == nil {
os.Setenv("GO_DEB_CUSTOM", "true")
debpath, _ = os.Getwd()
} else {
- debpath = filepath.Join(homeDir, "go/src", argv.Repo)
+ debpath = me.repo.GetFullPath()
}
+ _, basename := filepath.Split(debpath)
+ me.goPath = basename
os.Chdir(debpath)
// scan the repo
- cBox.addRepo(argv.Repo)
+ me.cBox.addRepo()
// look for a 'config' file in the repo
- if cBox.readControlFile() == nil {
+ if me.cBox.readControlFile() == nil {
log.Warn("scan worked")
} else {
log.Warn("scan failed")
}
- cBox.computeControlValues()
+ me.cBox.computeControlValues()
// verify the values for the package
- if repo == nil {
- if argv.Repo == "." {
- // this means try the local directory for a custom 'control' file
- } else {
- log.Info("argv.Repo =", argv.Repo)
- log.Info("repo not found. Try:")
- log.Info("")
- log.Info(" go-clone", argv.Repo)
- log.Info("")
- os.Exit(-1)
- }
- }
-
- // set the working directory to argv.Repo
- log.Info("cd", repo.FullPath)
- os.Chdir(repo.FullPath)
-
if argv.Auto {
shell.TestTerminalColor()
// basicWindow.Show() // broken gui package. convert to protobuf
- if ok, err := cBox.buildPackage(); ok {
+ if ok, err := me.cBox.buildPackage(); ok {
log.Info("build worked")
} else {
log.Warn("build failed:", err)
@@ -111,15 +94,7 @@ func main() {
os.Exit(0)
}
- // run the debugger if triggered from the commandline
- if debugger.ArgDebug() {
- go func() {
- log.Sleep(2)
- debugger.DebugWindow()
- }()
- }
-
- basicWindow.Show()
+ me.basicWindow.Show()
// go will sit here until the window exits
gui.Watchdog()
os.Exit(0)