summaryrefslogtreecommitdiff
path: root/main.go
blob: dd5109c6b1f5d76159fb5466a5d4035337ade26f (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
121
122
123
124
125
126
package main

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

	"go.wit.com/gui"
	"go.wit.com/lib/debugger"
	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/lib/protobuf/forgepb"
	"go.wit.com/log"
)

// sent from -ldflags
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)
	}
	forge = forgepb.Init()
	os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())

	repo = forge.FindByGoPath(argv.Repo)
	if repo == nil {
		log.Info("repo not found. you need to clone", argv.Repo)
		os.Exit(-1)
	}
	log.Info("found repo", argv.Repo)
	// build()

	myGui = gui.New()
	if !argv.Auto {
		myGui.InitEmbed(resources)
	}
	myGui.Default()

	basicWindow = makebasicWindow()

	// todo: add the go.work file logic here
	homeDir, _ := os.UserHomeDir()
	var debpath string
	if argv.Repo == "." {
		os.Setenv("GO_DEB_CUSTOM", "true")
		debpath, _ = os.Getwd()
	} else {
		debpath = filepath.Join(homeDir, "go/src", argv.Repo)
	}
	os.Chdir(debpath)

	// scan the repo
	cBox.addRepo(argv.Repo)

	// look for a 'config' file in the repo
	if cBox.readControlFile() == nil {
		log.Warn("scan worked")
	} else {
		log.Warn("scan failed")
	}
	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 {
			log.Info("build worked")
		} else {
			log.Warn("build failed:", err)
			os.Exit(-1)
		}
		os.Exit(0)
	}

	// run the debugger if triggered from the commandline
	if debugger.ArgDebug() {
		go func() {
			log.Sleep(2)
			debugger.DebugWindow()
		}()
	}

	basicWindow.Show()
	// go will sit here until the window exits
	gui.Watchdog()
	os.Exit(0)
}