summaryrefslogtreecommitdiff
path: root/docs.go
blob: b5baca233bea0e394b11c9b9eda4ba6057e48b1b (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
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"go.wit.com/gui"
	"go.wit.com/lib/gui/repolist"
	"go.wit.com/lib/gui/shell"
	"go.wit.com/log"
)

func docsBox(vbox *gui.Node) {
	group := vbox.NewGroup("Docs")

	group.NewButton("make 'go.work' file", func() {
		me.autotypistWindow.Disable()

		goSrcDir := me.goSrcPwd.String()
		filename := filepath.Join(goSrcDir, "go.work")

		f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
		if err != nil {
			return
		}
		defer f.Close()
		fmt.Fprintln(f, "go 1.21.4")
		fmt.Fprintln(f, "")
		fmt.Fprintln(f, "use (")
		for _, repo := range repolist.AllRepos() {
			if repo.Exists("go.mod") {
				fmt.Fprintln(f, "\t"+repo.Status.GoPath())
			} else {
				log.Info("missing go.mod for", repo.Status.Path())
				repo.Status.MakeRedomod()
			}
		}
		fmt.Fprintln(f, ")")

		me.autotypistWindow.Enable()
	})

	group.NewButton("run pkgsite", func() {
		tmp := me.userHomePwd.String()
		tmpDir := filepath.Join(tmp, "go/src")
		os.Chdir(tmpDir)
		pkgsite := filepath.Join(tmp, "go/bin", "pkgsite")
		os.Unsetenv("GO111MODULE")
		go shell.Run([]string{pkgsite})
		shell.Run([]string{"ping", "-c", "3", "git.wit.org"})
	})

	group.NewButton("open docs in browser (localhost:8080)", func() {
		me.autotypistWindow.Disable()
		defer me.autotypistWindow.Enable()

		shell.OpenBrowser("http://localhost:8080")
	})
}