summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-11 01:53:14 -0500
committerJeff Carr <[email protected]>2025-09-11 01:53:14 -0500
commit602e1fc4aea522217775e5587fc1bd91dd3f060c (patch)
treedec2b3e9e80a2c7c5b52108ed03be14163120229 /config.go
parent2b3dfe540c6bac279067a4e2bdfe090d499be045 (diff)
redo config handling
Diffstat (limited to 'config.go')
-rw-r--r--config.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..01721d9
--- /dev/null
+++ b/config.go
@@ -0,0 +1,71 @@
+package main
+
+// functions to import and export the protobuf
+// data to and from config files
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+)
+
+func forgeConfigSave() error {
+ return config.ConfigSave(me.forge.Config)
+}
+
+func configInit() (*forgepb.ForgeConfigs, error) {
+ /*
+ // the default forged dir is /home/forge
+ if os.Getenv("FORGE_GOSRC") == "" {
+ os.Setenv("FORGE_GOSRC", "/home/forge")
+ }
+
+ if os.Getenv("FORGE_PATCHDIR") == "" {
+ os.Setenv("FORGE_PATCHDIR", "/var/lib/forged")
+ }
+ */
+
+ me.urlbase = argv.URL
+ if me.urlbase == "" {
+ me.urlbase = "https://go.wit.com/"
+ }
+ if os.Getenv("FORGE_URL") != "" {
+ me.urlbase = os.Getenv("FORGE_URL")
+ log.Info("got forge url", me.urlbase)
+ }
+ me.urlbase = strings.Trim(me.urlbase, "/") // track down why trailing '/' makes http POST not work
+
+ configs := new(forgepb.ForgeConfigs)
+ err := config.ConfigLoad(configs, ARGNAME, "forge")
+ if errors.Is(err, os.ErrNotExist) {
+ // if forgepb.FirstTimeUser() {
+ log.Info("You are running forge for the first time here")
+ // }
+ configs.ReposDir = "/home/forge"
+ configs.ReposPB = "/home/forge/repos.pb"
+ configs.PatchDir = "/var/lib/forged"
+ if err := forgeConfigSave(); err != nil {
+ return nil, err
+ }
+ log.Info("WARNING: made a new default config file here", configs.Filename)
+ okExit("")
+ }
+ if err != nil {
+ }
+ return configs, err
+}
+
+func sampleConfig(all *forgepb.ForgeConfigs) {
+ new1 := new(forgepb.ForgeConfig)
+ new1.GoPath = "go.wit.com"
+ new1.Writable = true
+ new1.Directory = true
+ all.Append(new1)
+
+ fmt.Println("first time user. adding an example config file with", len(all.ForgeConfigs), "repos")
+}