aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 19:48:09 +0200
committerTeddy Wing2017-06-03 20:53:14 +0200
commit43cf753e794c37a8422e42389b077f1d20edc7af (patch)
treeb5c5b64f8e339efe07b8e4b3c1d776e6da123f20
parentfa85a708dff621e4d75f19bdbd45bba5947685c0 (diff)
downloadtimetasker-43cf753e794c37a8422e42389b077f1d20edc7af.tar.bz2
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.
-rw-r--r--main.go22
1 files changed, 15 insertions, 7 deletions
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 {