pass config path in cmd args

This commit is contained in:
Daniel Liu 2022-01-06 18:41:55 -05:00
parent 2b6fe3e1a0
commit fe1d5116ab
3 changed files with 25 additions and 11 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"net"
"os"
@ -16,10 +17,23 @@ import (
"git.csclub.uwaterloo.ca/public/merlin/sync"
)
// get config path from command args
var CONFIG_PATH = "merlin-config.ini"
var DEFAULT_CONFIG_PATH = "merlin-config.ini"
func main() {
// custom help message
flag.Usage = func() {
w := flag.CommandLine.Output()
fmt.Fprintf(w, "USAGE: merlin [-h | --help] [--config=<config-path>]\n")
flag.PrintDefaults()
}
// parse command args
// if more are added can prob use a library
configPath := flag.String("config", DEFAULT_CONFIG_PATH, "alternate config file")
flag.Parse()
// check that merlin is run as mirror user
// check that mirror user has pid of 1001
@ -43,7 +57,7 @@ func main() {
repoIdx := 0
loadConfig := func() {
config.LoadConfig(CONFIG_PATH, doneChan, stopChan)
config.LoadConfig(*configPath, doneChan, stopChan)
logger.OutLog("Loaded config:\n" + fmt.Sprintf("%+v\n", config.Conf))
repoIdx = 0

View File

@ -2,8 +2,8 @@ package sync
import (
"path/filepath"
"testing"
"reflect"
"testing"
"git.csclub.uwaterloo.ca/public/merlin/config"
"git.csclub.uwaterloo.ca/public/merlin/logger"