]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go
Ability to override spool directory and logfile
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-daemon / main.go
index e6ec2d385648ae1c84c8e959cc381addbc3d8e92..de0a0b3bf62b10cd6b5a0e43e0bcd3a0d489240d 100644 (file)
@@ -22,7 +22,6 @@ package main
 import (
        "flag"
        "fmt"
-       "io/ioutil"
        "log"
        "net"
        "os"
@@ -41,14 +40,16 @@ func usage() {
 
 func main() {
        var (
-               cfgPath  = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
-               niceRaw  = flag.Int("nice", 255, "Minimal required niceness")
-               bind     = flag.String("bind", "[::]:5400", "Address to bind to")
-               maxConn  = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
-               quiet    = flag.Bool("quiet", false, "Print only errors")
-               debug    = flag.Bool("debug", false, "Print debug messages")
-               version  = flag.Bool("version", false, "Print version information")
-               warranty = flag.Bool("warranty", false, "Print warranty information")
+               cfgPath   = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+               niceRaw   = flag.Int("nice", 255, "Minimal required niceness")
+               bind      = flag.String("bind", "[::]:5400", "Address to bind to")
+               maxConn   = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
+               spoolPath = flag.String("spool", "", "Override path to spool")
+               logPath   = flag.String("log", "", "Override path to logfile")
+               quiet     = flag.Bool("quiet", false, "Print only errors")
+               debug     = flag.Bool("debug", false, "Print debug messages")
+               version   = flag.Bool("version", false, "Print version information")
+               warranty  = flag.Bool("warranty", false, "Print warranty information")
        )
        flag.Usage = usage
        flag.Parse()
@@ -65,19 +66,13 @@ func main() {
        }
        nice := uint8(*niceRaw)
 
-       cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+       ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
        if err != nil {
-               log.Fatalln("Can not read config:", err)
-       }
-       ctx, err := nncp.CfgParse(cfgRaw)
-       if err != nil {
-               log.Fatalln("Can not parse config:", err)
+               log.Fatalln("Error during initialization:", err)
        }
        if ctx.Self == nil {
                log.Fatalln("Config lacks private keys")
        }
-       ctx.Quiet = *quiet
-       ctx.Debug = *debug
 
        ln, err := net.Listen("tcp", *bind)
        if err != nil {