Skip to content

Commit

Permalink
add option -initonly to "mox localserve", to only create config files…
Browse files Browse the repository at this point in the history
… and then quit

for issue #89 by naturalethic
  • Loading branch information
mjl- committed Nov 2, 2023
1 parent 9896639 commit 81057ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions localserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 81057ee

Please sign in to comment.