From 70597d4b1f205f234ce6f02356684e3dd4e9ffc3 Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 16 Mar 2024 17:25:18 -0500 Subject: [PATCH] Add optional --config option --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 63aa09f..468169a 100644 --- a/main.go +++ b/main.go @@ -8,25 +8,27 @@ import ( "github.com/akamensky/argparse" ) +var config Configuration + func summary() { fmt.Println("Summary") } func main() { parser := argparse.NewParser("gitivity", "Command line tool to get Gitea statistics") - Summary := parser.NewCommand("summary", "Generate a summary of a user's activity.") + config_path := parser.String("c", "config", &argparse.Options{Required: false, Help: "Configuration file", Default: "./config.lua"}) parse_err := parser.Parse(os.Args) if parse_err != nil { fmt.Print(parser.Usage(parse_err)) + return } - config := Configuration{} - if err := config.Parse("config.lua"); err != nil { - panic("Failed to parse configuration file: "+fmt.Sprint(err)) + config = Configuration{} + if err := config.Parse(*config_path); err != nil { + panic("Failed to parse configuration file") } - fmt.Printf("config.servers: %v\n", config.servers) //client, err := gitea.NewClient(*server_name) //if err != nil {