Adds config file command-line option
parent
4cc05363f2
commit
a648072ab4
22
main.go
22
main.go
|
@ -236,16 +236,28 @@ func main() {
|
||||||
// First flush all the logs
|
// First flush all the logs
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
|
||||||
// Command-line option "--init-db" creates the table
|
// Command-line options
|
||||||
|
// "--init-db" creates the table
|
||||||
initDB := flag.Bool("init-db", false, "Create database table if not present without prompting")
|
initDB := flag.Bool("init-db", false, "Create database table if not present without prompting")
|
||||||
|
// Config file
|
||||||
configPath := flag.String("config", "jilo-server.conf", "Path to the configuration file")
|
configPath := flag.String("config", "", "Path to the configuration file (use -c or --config)")
|
||||||
|
flag.StringVar(configPath, "c", "", "Path to the configuration file")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// Choosing the config file
|
||||||
|
finalConfigPath := "./jilo-server.conf" // this is the default we fall to
|
||||||
|
if *configPath != "" {
|
||||||
|
if _, err := os.Stat(*configPath); err == nil {
|
||||||
|
finalConfigPath = *configPath
|
||||||
|
} else {
|
||||||
|
log.Printf("Specified file \"%s\" doesn't exist. Falling back to the default \"%s\".", *configPath, finalConfigPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Config file
|
// Config file
|
||||||
log.Println("Reading the config file...")
|
log.Printf("Using config file %s", finalConfigPath)
|
||||||
config := readConfig(*configPath)
|
config := readConfig(finalConfigPath)
|
||||||
|
|
||||||
// Connect to or setup the database
|
// Connect to or setup the database
|
||||||
log.Println("Initializing the database...")
|
log.Println("Initializing the database...")
|
||||||
|
|
Loading…
Reference in New Issue