add option -initonly to "mox localserve", to only create config files and then quit

for issue #89 by naturalethic
This commit is contained in:
Mechiel Lukkien 2023-11-02 14:10:04 +01:00
parent 9896639ff9
commit 81057ee685
No known key found for this signature in database
2 changed files with 16 additions and 0 deletions

2
doc.go
View file

@ -346,6 +346,8 @@ during those commands instead of during "data".
usage: mox localserve
-dir string
configuration storage directory (default "$userconfigdir/mox-localserve")
-initonly
write configuration files and exit
-ip string
serve on this ip instead of default 127.0.0.1 and ::1. only used when writing configuration, at first launch.

View file

@ -66,8 +66,10 @@ during those commands instead of during "data".
}
var dir, ip string
var initOnly bool
c.flag.StringVar(&dir, "dir", filepath.Join(userConfDir, "mox-localserve"), "configuration storage directory")
c.flag.StringVar(&ip, "ip", "", "serve on this ip instead of default 127.0.0.1 and ::1. only used when writing configuration, at first launch.")
c.flag.BoolVar(&initOnly, "initonly", false, "write configuration files and exit")
args := c.Parse()
if len(args) != 0 {
c.Usage()
@ -77,6 +79,18 @@ during those commands instead of during "data".
mox.FilesImmediate = true
if initOnly {
if _, err := os.Stat(dir); err == nil {
log.Print("warning: directory for configuration files already exists, continuing")
}
log.Print("creating mox localserve config", mlog.Field("dir", dir))
err := writeLocalConfig(log, dir, ip)
if err != nil {
log.Fatalx("creating mox localserve config", err, mlog.Field("dir", dir))
}
return
}
// Load config, creating a new one if needed.
var existingConfig bool
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {