about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenny Morrison <benmorrison@ttm.sh>2019-03-17 03:08:15 -0400
committerBenny Morrison <benmorrison@ttm.sh>2019-03-17 03:08:15 -0400
commit71c2204119fec738a270ed50ec313ff2c8d6dc39 (patch)
tree0b4df9ee457bad182b9bbc63f3afe594280a4c05
parentfb0852cd55fb17c34b816c6956b7f4e79bcdc44e (diff)
downloadgoofbot-71c2204119fec738a270ed50ec313ff2c8d6dc39.tar.gz
Added command line switches: specifying config file location, describe config file structure, list switches
-rw-r--r--main.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/main.go b/main.go
index d0ce58f..998e612 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,8 @@ package main
 import (
 	"bytes"
 	"encoding/json"
+	"flag"
+	"fmt"
 	"io/ioutil"
 	"log"
 	"os"
@@ -36,8 +38,27 @@ type Conf struct {
 }
 
 func main() {
-	//read the file into a byte array
-	jsonconf, err := ioutil.ReadFile("config.json")
+	//check for config file specified by command line flag -c
+	jsonlocation := flag.String("c", "config.json", "Path to config file in JSON format")
+	jsonformat := flag.Bool("j", false, "Describes JSON config file fields")
+	flag.Parse()
+	if *jsonformat == true {
+		fmt.Println(`Here is the format for the JSON config file:
+            {
+                "owner": "YourNickHere",
+                "chan": "#favchannel",
+                "server": "irc.freenode.net",
+                "port": 6697,
+                "nick": "goofbot",
+                "pass": "",
+                "user": "goofbot",
+                "name": "Goofus McBotus",
+                "ssl": true
+            }`)
+		os.Exit(0)
+	}
+	//read the config file into a byte array
+	jsonconf, err := ioutil.ReadFile(*jsonlocation)
 	checkerr(err)
 
 	// unmarshal the json byte array into struct conf