From e443aee7b3bb99cfc631f143ac7a97042af2e843 Mon Sep 17 00:00:00 2001 From: Gerdriaan Mulder Date: Sat, 27 Oct 2018 21:44:35 +0200 Subject: [PATCH] Optionally pass labels JSON via command line, fixes #1 --- main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index adbd74a..4075e67 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ package main import ( "encoding/json" + "flag" "fmt" "io/ioutil" "os" @@ -14,8 +15,13 @@ import ( ) func main() { - if len(os.Args) != 2 { - fmt.Printf("Usage: %s \n\n", os.Args[0]) + jsonFile := flag.String("json", "example.json", "Use this JSON file for user labels") + flag.Parse() + + if len(flag.Args()) != 1 { + fmt.Printf("Usage: %s [-json file] \n\n", os.Args[0]) + flag.PrintDefaults() + fmt.Println() fmt.Println("Don't forget to set the environment variable OCTOKIT_ACCESS_TOKEN.") return } @@ -28,7 +34,7 @@ func main() { userlabels := make([]UserLabel, 0) - json.Unmarshal(getJsonFromFile("example.json"), &userlabels) + json.Unmarshal(getJsonFromFile(*jsonFile), &userlabels) for i := 0; i < len(userlabels); i++ { if contains(labels, userlabels[i].Name) {