add config file support
This commit is contained in:
parent
6722b019ec
commit
43d653a8c0
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
// functions to import and export the protobuf
|
||||
// data to and from config files
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"go.wit.com/lib/config"
|
||||
"go.wit.com/lib/protobuf/forgepb"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func configSave() error {
|
||||
return config.ConfigSave(me.configs)
|
||||
}
|
||||
|
||||
func (me *mainType) configInit() error {
|
||||
if argv.Hostname != "" {
|
||||
HOSTNAME = argv.Hostname
|
||||
}
|
||||
|
||||
// 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.configs = new(forgepb.ForgeConfigs)
|
||||
err := config.ConfigLoad(me.configs, ARGNAME, "forge")
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
me.configs.ReposDir = "/home/forge"
|
||||
me.configs.ReposPB = "/home/forge/repos.pb"
|
||||
me.configs.PatchDir = "/var/lib/forged"
|
||||
if err := configSave(); err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
log.Info("made a default config file here", me.configs.Filename)
|
||||
okExit("")
|
||||
}
|
||||
if err != nil {
|
||||
badExit(err)
|
||||
}
|
||||
return err
|
||||
}
|
14
main.go
14
main.go
|
@ -4,7 +4,6 @@ import (
|
|||
"embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
|
@ -31,18 +30,7 @@ func main() {
|
|||
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
||||
me.pp = arg.MustParse(&argv)
|
||||
|
||||
if argv.Hostname != "" {
|
||||
HOSTNAME = argv.Hostname
|
||||
}
|
||||
|
||||
// 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.configInit() // reads in the config file
|
||||
|
||||
me.forge = forgepb.RawInitPB()
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@ var me *mainType
|
|||
|
||||
// this app's variables
|
||||
type mainType struct {
|
||||
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
||||
forge *forgepb.Forge // for holding the forge protobuf files
|
||||
myGui *prep.GuiPrep // the gui toolkit handle
|
||||
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
|
||||
forge *forgepb.Forge // for holding the forge protobuf files
|
||||
myGui *prep.GuiPrep // the gui toolkit handle
|
||||
configs *forgepb.ForgeConfigs // for holding the forge protobuf files
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue