From 71c2204119fec738a270ed50ec313ff2c8d6dc39 Mon Sep 17 00:00:00 2001 From: Benny Morrison Date: Sun, 17 Mar 2019 03:08:15 -0400 Subject: Added command line switches: specifying config file location, describe config file structure, list switches --- main.go | 25 +++++++++++++++++++++++-- 1 file 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 -- cgit 1.4.1-2-gfad0