From 43cf753e794c37a8422e42389b077f1d20edc7af Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 3 Jun 2017 19:48:09 +0200 Subject: main.go: Only call `maybeWriteConfig()` when `--write-config` is given We shouldn't automatically force writing the config file. Only do so if the user asks for it to be done. NOTE: there's a problem here, because `-p` is required but it shouldn't be in this specific case. --- main.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 895786d..a2fafc8 100644 --- a/main.go +++ b/main.go @@ -19,13 +19,6 @@ var config Config func main() { var err error - err = maybeWriteConfig() - if err != nil { - fmt.Println("Could not write config file") - fmt.Println(err) - os.Exit(1) - } - err = loadConfig() if err != nil { fmt.Println("Could not load config file") @@ -51,9 +44,24 @@ func main() { description := kingpin.Flag("description", "Description of work."). Short('m'). String() + write_config_description := fmt.Sprintf( + "Initialise a new config file template at %s", + configFile(), + ) + write_config := kingpin.Flag("write-config", write_config_description). + Bool() kingpin.Version(VERSION) kingpin.Parse() + if *write_config { + err = maybeWriteConfig() + if err != nil { + fmt.Println("Could not write config file") + fmt.Println(err) + os.Exit(1) + } + } + // Submit time entry project, ok := config.Projects[*project_alias] if !ok { -- cgit v1.2.3