From 7554f9f4527608e208d95c921e2925b64d6ffd66 Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Fri, 29 Dec 2017 23:10:43 -0800
Subject: [PATCH] Move config to a flag

---
 dyndnsd-client.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/dyndnsd-client.go b/dyndnsd-client.go
index def1809..3247e1d 100644
--- a/dyndnsd-client.go
+++ b/dyndnsd-client.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"github.com/joshbetz/config"
 	"io/ioutil"
@@ -27,7 +28,17 @@ func init() {
 	logger.Println("PINGING dyndnsd ENDPOINT")
 
 	// Configuration
-	cfg = config.New("config.json")
+	var configPath string
+	flag.StringVar(&configPath, "config", "", "Config file path")
+	flag.Parse()
+
+	if _, err := os.Stat(configPath); os.IsNotExist(err) {
+		fmt.Println("Config path does not exist. Aborting!\n")
+		flag.Usage()
+		os.Exit(3)
+	}
+
+	cfg = config.New(configPath)
 	cfg.Get("ipv4_endpoint", &ipv4Endpoint)
 	cfg.Get("ipv6_endpoint", &ipv6Endpoint)
 }
-- 
GitLab