summaryrefslogtreecommitdiff
path: root/goWork.go
blob: 9310f0416f7d0eea1ad7558fe2a77af773f2edba (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
package forgepb

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

// very much a hack job
func (f *Forge) MakeGoWork() error {
	if f.IsGoWork() {
		// a go.work file was found
	} else {
		// you can use a go.work file in ~/go/src , but you probably shouldn't unless something
		// has gone terribly wrong
		return errors.New("if you want a go.work file in ~/go/src/, touch it first")
	}
	filename := filepath.Join(f.GetGoSrc(), "go.work")
	workf, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		return err
	}
	defer workf.Close()

	fmt.Fprintln(workf, "go 1.21") // fix this
	fmt.Fprintln(workf, "")
	fmt.Fprintln(workf, "use (")

	all := f.Repos.SortByFullPath()
	for all.Scan() {
		repo := all.Next()
		/*
			if !repo.IsGoLang() == "" {
				// skip repos that aren't go
				// todo: handle non-flat repos?
				log.Info("skip non-go", repo.GetGoPath)
				continue
			}
		*/
		if repo.GetGoPath() == "" {
			continue
		}
		fmt.Fprintln(workf, "\t"+repo.GetGoPath())
		/*
			if repo.pb.Exists("go.mod") {
				// log.Info("ADDING REPO", goSrcDir, repo.GetGoPath())
			} else {
			fmt.Fprintln(workf, "\t"+repo.GetGoPath)
				log.Log(REPO, "missing go.mod for", repo.GetGoPath())
			}
		*/
	}
	fmt.Fprintln(workf, ")")
	return nil
}